fixed aggregate function bug