chapter 4 exercise refactor