Move self labeling logic to label_line function