Yet another finite state machine implementation