Fixed dual-endpoint state machine, more refinement on issue #31 fix.