Refactor, runs in 57 seconds