Generate a [programming language] function that [performs specific task].
1. **Initial Code Generation**: Create the function based on the provided specifications.
2. **Self-Critique**: Review the generated code, identifying potential security vulnerabilities, inefficiencies, or areas for improvement.
3. **Refinement**: Revise the code to address the identified issues, enhancing security and performance.
4. **Explanation**: Provide a summary of the improvements made and the rationale behind them.
This prompt guides the AI to iteratively generate, critique, and refine code, enhancing security and functionality through self-assessment and improvement.