aggregation helper functions written in c