Make format-url more robust