Faster solution, but still raw
Cleanup solution