Use foldl instead of doing it manually.