careful about the last segment length