First working version of statemachine builder