Small refactor of Problem 6