Tweaked chain-finding logic.

Previous chain-finding wrapped into previous commit