refactored more, runs in 6.09s