Fix logic error in FirstInChain handling

A possible fix for firstinchain not working.

Some testing seems to show that this fixes issue #14 (at least the actual bug described there), but more review is needed.