Diverse bugfixes and improvements