Fixed the NaN problem when the distance is not shared.