Properly close file streams