Fix bugs in mailbox_state handling