diff --git a/japan_postal_code.module b/japan_postal_code.module
index 2b20960..aadfc2b 100644
--- a/japan_postal_code.module
+++ b/japan_postal_code.module
@@ -1,5 +1,6 @@
 <?php
 
+use Drupal\Core\File\FileSystemInterface;
 /**
  * @file
  * Provides japan postal code functionalities.
@@ -126,29 +127,31 @@ function _japan_postal_code_fetch_post_office_csv($type) {
   }
 
   // Prepare a file name for the zip file in temp directory.
-  $filepath_zip = drupal_tempnam(file_directory_temp(), '');
+  $filepath_zip = drupal_tempnam(\Drupal::service('file_system')->getTempDirectory(), '');
   if (!$filepath_zip) {
-    drupal_set_message(t('Cannot create a temp file: @filepath.',
-      ['@filepath' => $filepath_zip]), 'error');
+    \Drupal::messenger()->addError(t('Cannot create a temp file: @filepath.',
+      ['@filepath' => $filepath_zip]));
     return FALSE;
   }
 
   // Download the zip file from Japan post office website.
-  $result = system_retrieve_file($url, $filepath_zip, FALSE, FILE_EXISTS_REPLACE);
+  $result = system_retrieve_file($url, $filepath_zip, FALSE, FileSystemInterface::EXISTS_REPLACE);
   if (!$result) {
-    drupal_set_message(t('Cannot retrieve the file from @url into @filepath.',
-      ['@url' => $url, '@filepath' => $filepath_zip]), 'error');
+    \Drupal::messenger()->addError(t('Cannot retrieve the file from @url into @filepath.',
+      ['@url' => $url, '@filepath' => $filepath_zip]));
     return FALSE;
   }
 
   // Unzip the downloaded zip file.
   $zip = new ZipArchive();
   if (!$zip) {
-    drupal_set_message(t('Cannot create ZipArchive class instance.'), 'error');
+    \Drupal::messenger()->addError(t('Cannot create ZipArchive class instance.'));
     return FALSE;
   }
   $result = $zip->open($filepath_zip);
   if (!$result) {
+    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
+    // This needs to be replaced, but Rector was not yet able to replace this because the type of message was set with a variable. If you need to continue to use a variable, you might consider using a switch statement.
     drupal_set_message(t('Cannot open the zip file: @filepath.'),
       ['@filepath' => $filepath_zip], 'error');
     return FALSE;
@@ -156,6 +159,8 @@ function _japan_postal_code_fetch_post_office_csv($type) {
   $filepath_unzipped = $filepath_zip . '-unzipped';
   $result = $zip->extractTo($filepath_unzipped);
   if (!$result) {
+    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
+    // This needs to be replaced, but Rector was not yet able to replace this because the type of message was set with a variable. If you need to continue to use a variable, you might consider using a switch statement.
     drupal_set_message(t('Cannot extract the zip file: @filepath.'),
       ['@filepath' => $filepath_zip], 'error');
     return FALSE;
@@ -165,11 +170,11 @@ function _japan_postal_code_fetch_post_office_csv($type) {
   // Check the existence of and return the name of the extracted csv file.
   $filepath_csv = $filepath_unzipped . '/' . $filename_csv;
   if (!file_exists($filepath_csv)) {
-    drupal_set_message(t('Cannot unzip @filepath_unzipped into @filepath_csv',
+    \Drupal::messenger()->addError(t('Cannot unzip @filepath_unzipped into @filepath_csv',
       [
         '@filepath_unzipped' => $filepath_unzipped,
         '@filepath_csv' => $filepath_csv,
-      ]), 'error');
+      ]));
     return FALSE;
   }
 
@@ -191,6 +196,8 @@ function _japan_postal_code_fetch_post_office_csv($type) {
  */
 function _japan_postal_code_load_postal_code_csv($filepath, $type) {
   if (!file_exists($filepath)) {
+    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
+    // This needs to be replaced, but Rector was not yet able to replace this because the type of message was set with a variable. If you need to continue to use a variable, you might consider using a switch statement.
     drupal_set_message(t('Cannot find the file @filepath'), [
       '@filepath' => $filepath,
     ], 'error');
@@ -199,6 +206,8 @@ function _japan_postal_code_load_postal_code_csv($filepath, $type) {
 
   $f = fopen($filepath, 'r');
   if (!$f) {
+    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
+    // This needs to be replaced, but Rector was not yet able to replace this because the type of message was set with a variable. If you need to continue to use a variable, you might consider using a switch statement.
     drupal_set_message(t('Cannot open the file @filepath'), [
       '@filepath' => $filepath,
     ], 'error');
@@ -337,7 +346,9 @@ function _japan_postal_code_insert_postal_codes(array $postal_codes) {
   // and bulk insert them into database table for performance reason.
   $postal_codes_chunks = array_chunk($postal_codes, 1000);
   foreach ($postal_codes_chunks as $postal_code_chunk) {
-    $query = db_insert('japan_postal_code')
+    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
+    // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
+    $query = \Drupal::database()->insert('japan_postal_code')
       ->fields([
         'postal_code',
         'prefecture',
@@ -387,7 +398,9 @@ function japan_postal_code_get_addresses_by_postal_code($postal_code) {
     $postal_code = str_replace('-', '', $postal_code);
   }
 
-  $query = db_select('japan_postal_code', 'jpc')
+  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
+  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
+  $query = \Drupal::database()->select('japan_postal_code', 'jpc')
     ->fields('jpc')
     ->condition('postal_code', $postal_code, '=');
 
@@ -425,7 +438,9 @@ function japan_postal_code_get_address_by_postal_code($postal_code) {
     $postal_code = str_replace('-', '', $postal_code);
   }
 
-  $query = db_select('japan_postal_code', 'jpc')
+  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
+  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
+  $query = \Drupal::database()->select('japan_postal_code', 'jpc')
     ->fields('jpc')
     ->condition('postal_code', $postal_code, '=')
     ->range(0, 1);
@@ -464,7 +479,9 @@ function _japan_postal_code_is_valid_postal_code($postal_code) {
  *   number of the postal code records in the db table `japan_postal_code`.
  */
 function _japan_postal_code_count_postal_code_records() {
-  $query = db_select('japan_postal_code', 'jpc')->countQuery();
+  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
+  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
+  $query = \Drupal::database()->select('japan_postal_code', 'jpc')->countQuery();
   $count = $query->execute()->fetchField();
   return $count;
 }
diff --git a/src/Form/ConfigForm.php b/src/Form/ConfigForm.php
index 38cd120..41535d4 100644
--- a/src/Form/ConfigForm.php
+++ b/src/Form/ConfigForm.php
@@ -50,10 +50,10 @@ class ConfigForm extends FormBase {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $count = _japan_postal_code_update_all_postal_code();
     if ($count === FALSE) {
-      drupal_set_message($this->t('Japan postal code database table update failed.'), 'error');
+      $this->messenger()->addError($this->t('Japan postal code database table update failed.'));
     }
     else {
-      drupal_set_message($this->t('Japan postal code database table is successfully updated. %count address inserted.', ['%count' => $count]));
+      $this->messenger()->addStatus($this->t('Japan postal code database table is successfully updated. %count address inserted.', ['%count' => $count]));
     }
   }
 
