convert ui behaviour to state machines