Added check for undefined property `state` before moving its value and unsetting it if it has been set.