refactor duplicate code
simplify country search logic