chapter 9 exercise 9 add refactored solution