Refactor email sub