Simplification of replaceWith method