Bugfxes, added test suite