Added better parameter handling and safe search/replace function