reimplemented state machine