Fixed some logic bugs in filter