Improved find and replace functions