Added final inserting document step.