update prependDoc
add defensive check