Updated weightByDist to calculate and store all pairwise distances