Safer writing of files
Add shutdown function back
Removed unused variable
Add safe credential gathering
Unused funcs