Cleanup and bugfix pairing code.