A bit more efficient distance calculation.