Lots of different fixes and improvements