Minor refactoring in segment.py