new alg. bug fixed