Refactor chapter 4 examples