Added improved check for invalid URLS