Segment creation function.