updated way of counting depth for subqueries, now it counts the layers of nested subqueries, preventing a one off error