added email and file logging for error handling