fixes to chapter 5 code