fix treatment of aggregate clauses