cleaned up the findNextInChain function