refine state-machine case study