Modified controller to be thread-safe state machine