Implement new state and type filters.

Fixes #5906