What is a state machine?