update algorithm to generate balanced pairs