Consolidated filtering. Hope I did not screw things up too much