Fix boolean filtration, add tests, refactoring