alg1 and alg2 working correctly