Implemented simple finite state machine