tested reduce and reduceRight, fixed bugs