Thread safe disconnect.
Some more thread safety added.