refactor clean_url function (re #254)