Main linking algorithm possibly works right.
More hard test cases is required.
Recursive variant of algorithm is added.