Even more refactoring on Prob 17
Refactor Problem 18