got better runtime out of problem 6