update the distance and the result