added proper errored document handling