Refactored, runs in 6.38s