finished distance matrix computation function