revised binary search

maybe have bugs