Actually, why not put all this functionality outside, where writeEmbed and writeEmbedShell are located? Then you just need to create the html, and store.write() it.