Architecture refactor

Use the new architecture, and only attach elements to the document at the last possible moment to avoid flickering effects