refactored, executes in 4.8s