Handling connect, disconnect and reconnect