Write the metadata last, otherwise if the keys fail to write we're FUBAR