Added aggregateRowsBy for #157
Clean up logic a bit for #157