clean up file closing code