use foldl' instead of foldr, don't call canonize unless needed