Fixed bugs in min/max/avg functions.