more optimise statemachine