fixed bugs from chapter 5