Here’s my working code. It works, but it’s ugly.
[paste your code]
Refactor it. Priorities in this order:
- Readability — someone else should understand it in 30 seconds
- Maintainability — easy to change later without breaking things
- Performance — only if there’s a real bottleneck, not micro-optimizations
Keep the same behavior. If you change any interface or signature, call it out explicitly so I don’t miss it.