added feature to check before close file.