Backport reimplementation of -aggregate: from 3.0-development

Less code :arrow_down_small: