fixed inconsistent breaking; other refactoring

the sets of Segment* 's needed to be sorted consistently