Few refactorings of Problem 3