First implementation, binary search