Properly close files