Refactor to use urlparse.