Code cleanup and fixes.