Refactor DOM rendering and copy/paste support