adjusted code for chapter 7