Fix crash when reconnecting