refactor chapter 17