improve perf.
use foldLeft
Merge branch 'vars'