many bugfixes and testing