mail refactoring