added the state machine and mailer