Selection filter

This is the second go at the selection filter.
The previous approach can be found at PR #954.