Fixes subquery problem