Changing name of routine from apply to reduce (which is more accurate) and adding test.