optimizing condensed distances