Added better error handling for URL parsing