Lots of small fixes and improvements