Fixed the algorithm again