Fix bug in filtering

Fixes all tests