Finish code for chapter 7