Refactor exercise chapter 9