Fixed bug when constructing document object