First rewrite of the algorithm
Starting debugging the algorithm