optimize, add yield in algorithms