Fix bug in `StateFilter.return_expanded()` and add some tests.