Port aggregate changes from core
Changelog and version bump to 3.40