Adding code for Chapter 5 exercises