Simplify replaceWith method. Closes gh-1276