Implement minimization for StateMachine and update shapes in visualization