improve shutdown sequence