Update of dinstance calculation. Reversed due to bug
Merged