Fix shutdown behavior