more generalization of algorithm