modified binary search