many misc fixes and improvements