fixed bugs in edgecases