Bug is fixed

Looks like now the algorithm is coded properly. If this is really so, it
is time for regression tests, code cleaning and documentation.