improve connection/disconnection detection