fix document handling