Revised filtering logic