add code for chapter 6