Refactor some serial aggregation code and add support for index scan serial aggregation