more accurate calculation of the distance