change code for new algorithm