Restructures the document.