A lot of fixes and improvements