Fixed random exceptions being thrown and non-handled empty document corner case.