Added extra check so that duplicate nodes are not added to children