problem 2 refactored