First attempt at fixing at least the rectangular distance function.