Calculating the distance properly.