fixed file closing problems