refactor chapter 9