problem 16. starting work to refactor it