adding cost and distance