Lots of little fixes, plus chapter 9 example.

What does this do and why is it needed?