Code cleanup and a DoURL fix for when $detect_urls is true.