refactor apply filter to use substitution