Used foldl'
Use foldr
Extract function