fix file not closing bug