completed state machine logic