problem 10
refactored problem 7