Notes and code for chapter 7