New algorithm. Without rolgangs. Completed