Fix slow filtering issue