working on an efficient way to populate distance matrix