cleanup and several fixes