implement using a binary search