Better pair generation function