fix for nil document