Fix incorrect implementation of foldr'