refactoring archive aggregate calculations, and adding tests