Optimizing sumPairs