Add tests and fix for filter bug