Tag finite-state machine