add do_filter func to reduce duplicated code