Rewrite CMRI decoding routine to use a state machine