Replaced use of outerHTML (and added tests for new function)