reimplement defensive as a binary search