fix incorrect calculation in isEnd for reverse search