refactor use of filter