Code for Chapter 8