simplify binary search code