added code for chapter 2