Hacked in fix for $max_distance