Replace for-loop with std::transform() for deep copy.
Remove one-time-use nNodes.
Replace for loop with std::for_each.