partially implemented alg2