Fixed segfault where the doc might be null