Major bugfix collect pairs algorithm