Minor refactoring, moved mailer functionality to a separate file