refactored country code util function