Solved problem 27
Improved solution to problem 27