Way better binary search courtesy of @jonathanvoss