Adding chapter 6 code