alter segDoc() algorithm