fix filtering logic