move function back out of aggregation