Implement chapter 8 code