Make URL parsing more robust