Refactor to support email notifications