refactor problem 3 answer