changed partDistMatrix so we only need O(n) memory instead of O(n^2)