Fix shutdown function.