add cases when commandFailed. improve state machine.