add bugfixes and tests