added the state machine and fixed bug where there’s a spiral recognition pattern