Fixed cost_distance and added test cases.