added simple state machine