consolidate duplicated distance calculations