Added more accurate calculation for first-node distance