Cleanup and fix some minor bugs.