Rework the filtering. Fixes #3