a better binary search implementation