Tested the algorithm - now working!