Updated a few function to use map and foldr insteaf of recursion.