added folding and reducing functions