Fix aggregate functions
Merge branch 'master' into lucas