Minor bug fixes.

I have fixed some minor bugs I have found while reading the source code. Small bugs which don't show up unless something really horrible has already happened.