initial set of fixes and cleanup