working on finite state machine