Distance calculating
merging