Moved the file processing outside the function.