added f.close() at end of file