adding chapter 4 code