Fixed bugs in the pairing process.