Adding formulas to distance calculation