add do_filter func to reduce duplicated code
Merge pull request #375 from pengfei-xue/devel

add do_filter func to reduce duplicated code