good refactoring (removing some conversions to matrix and back to data.frames...
Adding the aggregation step.