proper binary search