update the algorithm and put in classes