Refactor grains total to use reduce instead of map