Move country code normalization into a function

That way, we can write unit tests for it.