refactor rendering of document and group