moving collectedPairs code around