Is it possible to COMPLETE topGroupByExpressions so that it always has an alias and expression for every group by column in every case (original TVE or substitute TVE)  / (complexGroupBy or not)? 
That could eliminate the re-testing that has to happen to decide whether to use an element of topGroupByExpressions or to use the original col.expression. You could just always use the element from topGroupByExpressions.