fixed a bug of not closing file