Fixing up logic for filtering