Found the error, and fixed it. the algorithm now works!