Fix problems with the disconnect() function in some cases.