Refactor chapter 3