fixed file reading loop bug