Refactored connection handling into separate package, driven by a new FSM.