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.
+1 for more structure :)