new distance function for broadcast method and some other changes