roughly doing some aggregation and writing output
output looks reasonable