Major changes to adapt the code to new algorithms...
Now rec environment is autommatically shared.
Distance algorithm optimized.