Disconnect only when necessary