Fix bug in filter, add tests