Changes from mutable variable to immutable, using foldLeft now