State Machine Refined