Improved some code in chapter 5 exercises