# Code Refactoring Refactor the specified code with the following goals: 1. **Improve Readability** - Clear naming, logical structure, remove complexity 2. **Reduce Duplication** - Extract common patterns into reusable functions 3. **Enhance Maintainability** - Better separation of concerns, SOLID principles 4. **Optimize Performance** - Only if it doesn't sacrifice readability Guidelines: - Preserve existing behavior (no functional changes) - Keep existing tests passing - Add comments only where logic isn't self-evident - Prefer small, focused functions over large ones Output format: 1. Analysis of current issues 2. Refactoring plan 3. Refactored code with explanations 4. Summary of improvements