Updated filtering logic