refactor apply filtering