refactor the algorithm code to correct the fatal error
update for new
correct the variable NAME!