refactor chapter 8