several bugfixes and improvements