refactored problem1