Refactor Problem 18