Made the file detection code cleaner.