Correct distance function.