Add funct to handle the document stream