added checking for pairs and combining