Bug fix.

The state machine did not loop back on itself to other types when it was
supposed to.

Now it keeps track of state machines tied to elements that were
processed earlier, and links them.