Improve connect/disconnect logic
Improve connect/disconnect logic 2