fixed chapter 3 code