bugfixes and added test