Fix shutdown function