Use a better find and replace function.

This should fix your #1, doing a proper walk of the DOM and replacing anything it finds that matches.