a working algorithm

replace segment composition with window composition with merged segment