close files before using them