Adding code for chapter 4