refactored problem 11