Fix all the off-by-one and rounding bugs in aggregation