a simple finite state machine