Bug fix for data file closing