Replace for-loop with std::transform() for deep copy.
Use constant references instead of copies.
Remove one-time-use nNodes.
Replace for loop with std::for_each.