optimize filter.py, no need to buffer all the data in phase 3