A whole bunch of fixes and improvements throughout