Set metadata step and convergence cleanup

Move some of the cleanup code and the SetMetadataItem functionality from #727 to here, so #727 can be smaller.
This is probably not this PR but `NamedConstant` should be changed to `NodeTypes`?