refactor problem 4