use foldr to refactor map