add logging and emailing