reimplemented half of state machine