added the distance to function again