Fix somethings in the algorithm