fix distance matrix problems