fixed some corner cases