fixed a couple of bugs in pair-matching