more cleanup and bug fixes.