Adding code for chapter 8