--- a/src/slaptgpgme.c	2022-03-20 11:29:38.887089961 +0200
+++ b/src/slaptgpgme.c	2022-03-20 11:30:41.733939959 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003-2020 Jason Woodward <woodwardj at jaos dot org>
+ * Copyright (C) 2003-2022 Jason Woodward <woodwardj at jaos dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,10 +20,9 @@
 
 static gpgme_ctx_t *_slapt_init_gpgme_ctx(void)
 {
-    gpgme_error_t e;
     gpgme_ctx_t *ctx = slapt_malloc(sizeof *ctx);
 
-    e = gpgme_new(ctx);
+    gpgme_error_t e = gpgme_new(ctx);
     if (e != GPG_ERR_NO_ERROR) {
         fprintf(stderr, "GPGME: %s\n", gpgme_strerror(e));
         free(ctx);
@@ -52,14 +51,11 @@
 FILE *slapt_get_pkg_source_checksums_signature(const slapt_config_t *global_config, const char *url, bool *compressed)
 {
     FILE *tmp_checksum_f = NULL;
-    char *checksum_head = NULL;
     bool interactive = slapt_is_interactive(global_config);
+
     char *location_uncompressed = SLAPT_CHECKSUM_ASC_FILE;
     char *location_compressed = SLAPT_CHECKSUM_ASC_FILE_GZ;
-    char *filename = NULL;
-    char *local_head = NULL;
     char *location;
-
     if (*compressed) {
         location = location_compressed;
         *compressed = true;
@@ -68,104 +64,129 @@
         *compressed = false;
     }
 
-    filename = slapt_gen_filename_from_url(url, location);
-    local_head = slapt_read_head_cache(filename);
-    checksum_head = slapt_head_mirror_data(url, location);
-
-    if (checksum_head == NULL) {
-        if (interactive)
-            printf(gettext("Not Found\n"));
-        free(filename);
-        free(local_head);
-        if (checksum_head != NULL)
-            free(checksum_head);
-        return NULL;
-    }
+    char *checksum_head = slapt_head_mirror_data(url, location);
+    if (checksum_head != NULL) {
+        char *filename = slapt_gen_filename_from_url(url, location);
+        char *local_head = slapt_read_head_cache(filename);
+
+        if (local_head != NULL && strcmp(checksum_head, local_head) == 0) {
+            if ((tmp_checksum_f = slapt_open_file(filename, "r")) == NULL) {
+                exit(EXIT_FAILURE);
+            }
+
+            if (global_config->progress_cb == NULL) {
+                printf(gettext("Cached\n"));
+            }
 
-    if (local_head != NULL && strcmp(checksum_head, local_head) == 0) {
-        if ((tmp_checksum_f = slapt_open_file(filename, "r")) == NULL)
-            exit(EXIT_FAILURE);
+        } else {
+            if (global_config->dl_stats) {
+                printf("\n");
+            }
+
+            if ((tmp_checksum_f = slapt_open_file(filename, "w+b")) == NULL) {
+                exit(EXIT_FAILURE);
+            }
+
+            const char *err = slapt_get_mirror_data_from_source(tmp_checksum_f, global_config, url, location);
+            if (!err) {
+                if (interactive) {
+                    printf(gettext("Done\n"));
+                }
+
+            } else {
+                fprintf(stderr, gettext("Failed to download: %s\n"), err);
+                slapt_clear_head_cache(filename);
+                fclose(tmp_checksum_f);
+                free(filename);
+                free(local_head);
+                free(checksum_head);
+                return NULL;
+            }
+            /* make sure we are back at the front of the file */
+            rewind(tmp_checksum_f);
 
-        if (global_config->progress_cb == NULL)
-            printf(gettext("Cached\n"));
+            /* if all is good, write it */
+            slapt_write_head_cache(checksum_head, filename);
+        }
 
+        free(filename);
+        free(local_head);
+        free(checksum_head);
     } else {
-        const char *err = NULL;
+        char *filename = slapt_gen_filename_from_url(url, location);
 
-        if (global_config->dl_stats)
+        if (global_config->dl_stats) {
             printf("\n");
+        }
 
-        if ((tmp_checksum_f = slapt_open_file(filename, "w+b")) == NULL)
+        if ((tmp_checksum_f = slapt_open_file(filename, "w+b")) == NULL) {
             exit(EXIT_FAILURE);
+        }
 
-        err = slapt_get_mirror_data_from_source(tmp_checksum_f, global_config, url, location);
+        const char *err = slapt_get_mirror_data_from_source(tmp_checksum_f, global_config, url, location);
         if (!err) {
-            if (interactive)
+            if (interactive) {
                 printf(gettext("Done\n"));
+            }
 
         } else {
             fprintf(stderr, gettext("Failed to download: %s\n"), err);
             slapt_clear_head_cache(filename);
             fclose(tmp_checksum_f);
             free(filename);
-            free(local_head);
-            free(checksum_head);
             return NULL;
         }
         /* make sure we are back at the front of the file */
         rewind(tmp_checksum_f);
 
-        /* if all is good, write it */
-        slapt_write_head_cache(checksum_head, filename);
+        free(filename);
     }
-
-    free(filename);
-    free(local_head);
-
-    free(checksum_head);
-
     return tmp_checksum_f;
+
 }
 
 FILE *slapt_get_pkg_source_gpg_key(const slapt_config_t *global_config, const char *url, bool *compressed)
 {
     FILE *tmp_key_f = NULL;
-    char *key_head = NULL;
     char *filename = slapt_gen_filename_from_url(url, SLAPT_GPG_KEY);
     char *local_head = slapt_read_head_cache(filename);
     bool interactive = global_config->progress_cb == NULL && !global_config->dl_stats ? true : false;
 
     *compressed = false;
-    key_head = slapt_head_mirror_data(url, SLAPT_GPG_KEY);
+    char *key_head = slapt_head_mirror_data(url, SLAPT_GPG_KEY);
 
     if (key_head == NULL) {
-        if (interactive)
+        if (interactive) {
             printf(gettext("Not Found\n"));
+        }
         free(filename);
         free(local_head);
-        if (key_head != NULL)
+        if (key_head != NULL) {
             free(key_head);
+        }
         return NULL;
     }
 
     if (local_head != NULL && strcmp(key_head, local_head) == 0) {
-        if ((tmp_key_f = slapt_open_file(filename, "r")) == NULL)
+        if ((tmp_key_f = slapt_open_file(filename, "r")) == NULL) {
             exit(EXIT_FAILURE);
+        }
 
-        if (global_config->progress_cb == NULL)
+        if (global_config->progress_cb == NULL) {
             printf(gettext("Cached\n"));
+        }
 
     } else {
-        const char *err = NULL;
-
-        if ((tmp_key_f = slapt_open_file(filename, "w+b")) == NULL)
+        if ((tmp_key_f = slapt_open_file(filename, "w+b")) == NULL) {
             exit(EXIT_FAILURE);
+        }
 
-        err = slapt_get_mirror_data_from_source(tmp_key_f, global_config, url, SLAPT_GPG_KEY);
+        const char *err = slapt_get_mirror_data_from_source(tmp_key_f, global_config, url, SLAPT_GPG_KEY);
 
         if (!err) {
-            if (interactive)
+            if (interactive) {
                 printf(gettext("Done\n"));
+            }
         } else {
             fprintf(stderr, gettext("Failed to download: %s\n"), err);
             slapt_clear_head_cache(filename);
@@ -192,16 +213,15 @@
 
 slapt_code_t slapt_add_pkg_source_gpg_key(FILE *key)
 {
-    gpgme_error_t e;
-    gpgme_ctx_t *ctx = _slapt_init_gpgme_ctx();
-    gpgme_import_result_t import_result;
-    gpgme_data_t key_data;
     slapt_code_t imported = SLAPT_GPG_KEY_NOT_IMPORTED;
 
-    if (ctx == NULL)
+    gpgme_ctx_t *ctx = _slapt_init_gpgme_ctx();
+    if (ctx == NULL) {
         return imported;
+    }
 
-    e = gpgme_data_new_from_stream(&key_data, key);
+    gpgme_data_t key_data;
+    gpgme_error_t e = gpgme_data_new_from_stream(&key_data, key);
     if (e != GPG_ERR_NO_ERROR) {
         fprintf(stderr, "GPGME: %s\n", gpgme_strerror(e));
         _slapt_free_gpgme_ctx(ctx);
@@ -216,12 +236,13 @@
         return imported;
     }
 
-    import_result = gpgme_op_import_result(*ctx);
+    gpgme_import_result_t import_result = gpgme_op_import_result(*ctx);
     if (import_result != NULL) {
-        if (import_result->unchanged > 0)
+        if (import_result->unchanged > 0) {
             imported = SLAPT_GPG_KEY_UNCHANGED;
-        else if (import_result->imported > 0)
+        } else if (import_result->imported > 0) {
             imported = SLAPT_GPG_KEY_IMPORTED;
+        }
     }
 
     gpgme_data_release(key_data);
@@ -255,20 +276,21 @@
 
 slapt_code_t slapt_gpg_verify_checksums(FILE *checksums, FILE *signature)
 {
-    gpgme_error_t e;
-    gpgme_ctx_t *ctx = _slapt_init_gpgme_ctx();
-    gpgme_data_t chk_data, asc_data;
     slapt_code_t verified = SLAPT_CHECKSUMS_NOT_VERIFIED;
 
-    if (ctx == NULL)
+    gpgme_ctx_t *ctx = _slapt_init_gpgme_ctx();
+    if (ctx == NULL) {
         return SLAPT_CHECKSUMS_NOT_VERIFIED_NULL_CONTEXT;
+    }
 
-    e = gpgme_data_new_from_stream(&chk_data, checksums);
+    gpgme_data_t chk_data;
+    gpgme_error_t e = gpgme_data_new_from_stream(&chk_data, checksums);
     if (e != GPG_ERR_NO_ERROR) {
         _slapt_free_gpgme_ctx(ctx);
         return SLAPT_CHECKSUMS_NOT_VERIFIED_READ_CHECKSUMS;
     }
 
+    gpgme_data_t asc_data;
     e = gpgme_data_new_from_stream(&asc_data, signature);
     if (e != GPG_ERR_NO_ERROR) {
         gpgme_data_release(chk_data);
