More cleanups and bug fixes.