Refactor problem 3