Code for Chapter 2