more aggregrate optimizations