Review this code for refactoring opportunities. I'm not looking for style nitpicks — focus on structural issues:
1. **Coupling & Cohesion** — what's tangled together that shouldn't be, what's split apart that should be unified?
2. **Hidden Complexity** — where is the code more complicated than the problem requires?
3. **Failure Modes** — what happens when this code encounters unexpected input, and is that handled deliberately or by accident?
4. **Proposed Refactor** — show the restructured version of the most important 1-2 issues, with a brief explanation of why it's better, not just different
5. **What NOT to change** — tell me what's actually fine as-is, so I don't over-refactor working code
Language: [LANGUAGE]
Context: [WHAT THIS CODE DOES, ANY CONSTRAINTS LIKE PERFORMANCE OR TEAM FAMILIARITY]
Code:
[PASTE CODE]