refactor chapter 7