moved logic from mailer to model