Fix shutdown issues