Fix shutdown

This will fix almost all shutdown issues