Lots of critical fixes and improvements