Added logging and email of critical errors