use foldl instead of foldr