introduce starting_segment_indices to keep track of starting segment of
each stack; treat stack_number as instance variable, most operations are
required to operating within the context of a stack_number