simplify distance matrix computation