Moved almost all side-effects out of the state machines into the
connection actor.