fix the problem in algorithm