Added the fix for file I/O from a thread