Refactor document structure