Fix shutdown bug