Function patchDocument