modified filtering logic