removed duplicates from distances
now distance templates work well