Added functionality to write metadata to disk.