sum function now implemented using reduce(...).