adding support for mailbox, organizing code