many bugfixes and improvements