changed file open to use the "with" construct