full rewrite, segmented