Add support for variable number of segments.