Add distances and threshold termination.