finishes the filter function.