Moving port handling out of create_uri.