Minor bug fixes.

Just fixed a few bugs I found while looking through the code.