close files before return