fix file closing