a simple state machine