Distance algorithm starting to work