add code to chapter 8