Algo change to match the whole chain, not just the prefix.

And more tests