Split inner method into text and html, added recursive traversal, added flatten method