refactoring function filterFiles