fixed distance matrix bug