refactor chapter 5