adding code for chapter 6