rename variable distance to distance_end;