begin the close file function