Fix logic error in FirstInChain handling

A possible fix for firstinchain not working.

Some testing seems to show that this fixes issue #14, but more review is needed.