Distance algorithm changed