fix shutdown sequence