Reworked document opening.