fix a bug in binary search