fixed subquery filtering