fix bugs from chapter 6