code from chapter 5