Improve the filter processing function