get correct ordering of segments