Fixed connection/disconnection issue. Added event hooks for connected, disconnected, and disconnecting events.