fix not turning document into string, add more check statements