properly close files using with statement