Refactoring mailsender code