Refactor cleanURL functionality.