clean up handling of URLs to properly encode parameters