refactor problem 2