fix various issues with segment concatenation, etc.