Updated correct formula for distance