Loads of bugfixes and improvements