Correctly close the files