added distance matrix function