Code for Chapter 6