math: moved distance for pairs calculations to a function; renamed pair_t