event-driven finite state machine