Refactor chapter 4