add max_distance func