inlined addNodes function