Solved problem 12, still to optimize