changed file open to a with statement