refine filtering logic