Refactor email process