add new doctests, fix fold, reimplement sum with fold