rather than complicate handleOrderBy with this flag, you could handle the complexAgg case here:

    if (complexAgg) {
        agg = root.left
        ...
        agg = handleOrderBy(agg);
        ...
    }
    else {
        root = handleOrderBy(root);
    }