Small refactor of Problem 5