Fix memory leak and allow importing/exporting of files.