Improved Modularity introducing the notion of cache, that couldbe inserted inside a DistanceFunction.
Some test cases added