Created attachSubddg and adjustNodeIds functions