fixbug for metadata writting