added state machine for handling automatic mode