a lot of fixes and improvements