fix bug that occurs when closing files and reopen a new one