several fixes and improvements