Add local cache for country values.
Fix some notice.
Refactoring to reduce cyclomatic complexity.