fixed some bugs in pairing