Changed the algorithm