added control of state of machine