refactor stream filtering