Refactor segmented control code, reference #82