factor out common code in the metadata builders