Add support for Avg/Sum reductions, fixes #26, fixes #27