updated logic for filtering