Refactoring to prevent multiple enumerations through the files
Refactoring to make code more concise and hopefully more efficient when dealing with large amounts of files