working code for filtering