More fixes for int->long change in ID handling. New distance matrix method