Tidied up code for problem 60 solution