make sure to write Metadata correctly if set