Handles malformed URLs better
More robust handling of malformed URLs.