refactored problem 1