Fixed the algorithm...I think