A simple dynamic state machine for handling on-the-fly state management