Make sure the metadata file is closed

This is to make sure the file is always closed. (Memory leak?..)