- Using foldLeft consistently for sum and product
- Removed code duplication