fixed script, now handles URL replacement properly