various bugfixes and improvements