fix error when using aggregates