Added state machine for different actions.