Refactor problem 7