Handle the closing of the last file correctly