Fix shutdown sequence.