Minor bug fixes.
Cleaned up the code.