Previously files were not deleted correctly, because the code tried to delete the file while a file-stream was still open.