Misc code cleanup and fixes.