refactor chapter 16 examples and exercise