Bug fix.
Extend AverageTest to check if everything is cleaned up.
Aggregatefunction memory bug fix.