refactor chapter 6