added close for both input and output files