Refactored the solution to Problem 150 a bit.