Fixed some main problems

Added the possibility to choose total aggregation function (Sum, Count,
Average, etc.).
Fixed the problem with aggregation when no user interaction