several fixes and cleanup