for loop is a mess for distance matrix