added state machine for controller