added chapter 3 code