Clean up distance calculation.