This is the code for chapter 5