Handle first and last segments of a line