Indirect filtering rewritten. All test cases pass.