Reimplemented sum and product with foldl.