Do some refactoring in Pen._add_segment.