Stability fixes

Small stability fixes to stop the scripts crashing if they are unable to log to email or postgres.