Fix bug in chapter 5.2 code