bugfixes, added more tests