Refactor Problem 6