Refactor map to use foldl.