Collapsing linear sequences of states; fixed a bug in isLocal