refactors code, allows segments to be generated in document model, with overlapping segments