This looks like a foldLeft over Nil to me