safe version of fold_right