Logic for creating chains.