Refactored code in make_chains().