refactor chapter 8 examples