FIX: the total distances are calculated in a redundant way