move file processing code into utility function