A bunch of fixes and improvements