Fixed the adaptive calculation of distances. (For the record: when a lambda is called, all external variables should be instantiated using ‘default arguments’— i.e. (lambda i=i: dis[i]) — )