refactoring email handling