Improve connect/disconnect handling