bugfix

fixed a bug in checking ig edges are connected and catch exceptions on
distance function
added test of distance