Support for 2012 aggregate functions and various fixes