refactor state machine lite