Added check for empty doc