Improved behaviour with many (thousands) of input files.
Fixed tests.