fix dsitance calculation