chapter 7 refactor