fix distance calculation.