Refactor Problem 4 to be a little cleaner