Revise code for filtering