fixed some corner cases, more tests