Implemented connect/disconnect logic.