Fixing distance calculation formula.