Simplify and improve binary search