added state machine and a mailer