Fix KeepMetadata function