Refactor three_pairs