refactor chapter 3