Added some code to try and optimize the scanFile() function but it is not quite working yet