Revised the distance calculation