fix stopping when close to the minimal distance