added some code snippets from chapter 2