Correctly cleanup open files