Code for Chapter 3