code refactored, additional robustness in file collection