Updated version of sum_pairs