bunch of fixes and improvements