Various fixes and improvements