fixed bug, added tests