source code for chapter 3