new structure of the algorithm. comment out tests