Refactor to use an FSM.
Fix a bug where queued messages got sent to the wrong place.