some cleanups and bug fixes.