diff --git a/gtk/gtkprintbackend.c b/gtk/gtkprintbackend.c
index ab170a9..addbafc 100644
--- a/gtk/gtkprintbackend.c
+++ b/gtk/gtkprintbackend.c
@@ -682,10 +682,10 @@ gtk_print_backend_set_password (GtkPrintBackend  *backend,
 
 static void
 store_auth_info_toggled (GtkCheckButton *chkbtn,
-                         gpointer   user_data)
+                         gpointer        user_data)
 {
   gboolean *data = (gboolean *) user_data;
-  *data = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (chkbtn));
+  *data = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chkbtn));
 }
 
 static void
@@ -714,7 +714,7 @@ password_dialog_response (GtkWidget       *dialog,
   if (response_id == GTK_RESPONSE_OK)
     gtk_print_backend_set_password (backend, priv->auth_info_required, priv->auth_info, priv->store_auth_info);
   else
-    gtk_print_backend_set_password (backend, priv->auth_info_required, NULL, priv->store_auth_info);
+    gtk_print_backend_set_password (backend, priv->auth_info_required, NULL, FALSE);
 
   for (i = 0; i < g_strv_length (priv->auth_info_required); i++)
     if (priv->auth_info[i] != NULL)
@@ -830,12 +830,12 @@ request_password (GtkPrintBackend  *backend,
 
   if (can_store_auth_info)
     {
-        chkbtn = gtk_check_button_new_with_label (_("Remember Password"));
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chkbtn), FALSE);
-        gtk_box_pack_start (GTK_BOX (vbox), chkbtn, FALSE, FALSE, 6);
-        g_signal_connect (chkbtn, "toggled",
-                          G_CALLBACK (store_auth_info_toggled),
-                          &(priv->store_auth_info));
+      chkbtn = gtk_check_button_new_with_label (_("Remember password"));
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chkbtn), FALSE);
+      gtk_box_pack_start (GTK_BOX (vbox), chkbtn, FALSE, FALSE, 6);
+      g_signal_connect (chkbtn, "toggled",
+                        G_CALLBACK (store_auth_info_toggled),
+                        &(priv->store_auth_info));
     }
 
   if (focus != NULL)
diff --git a/modules/printbackends/cups/gtkcupssecretsutils.c b/modules/printbackends/cups/gtkcupssecretsutils.c
index 63b7ec4..977961e 100644
--- a/modules/printbackends/cups/gtkcupssecretsutils.c
+++ b/modules/printbackends/cups/gtkcupssecretsutils.c
@@ -23,24 +23,30 @@
 
 #include "gtkcupssecretsutils.h"
 
-#define SECRETS_BUS "org.freedesktop.secrets"
+#define SECRETS_BUS              "org.freedesktop.secrets"
 #define SECRETS_IFACE(interface) "org.freedesktop.Secret."interface
-#define SECRETS_PATH "/org/freedesktop/secrets"
-#define SECRETS_TIMEOUT 5000
+#define SECRETS_PATH             "/org/freedesktop/secrets"
+#define SECRETS_TIMEOUT          5000
+
+typedef enum
+{
+  SECRETS_SERVICE_ACTION_QUERY,
+  SECRETS_SERVICE_ACTION_STORE
+} SecretsServiceAction;
 
 typedef struct
 {
-  GDBusConnection *dbus_connection;
-  gboolean         store_info;
-  gchar          **auth_info,
-                 **auth_info_labels,
-                  *printer_uri,
-                  *session_path,
-                  *collection_path;
-  GtkCupsRequest  *request;
-  GDBusProxy      *item_proxy;
-  guint            prompt_subscription;
-} secrets_service_data;
+  GDBusConnection       *dbus_connection;
+  SecretsServiceAction   action;
+  gchar                **auth_info,
+                       **auth_info_labels,
+                       **auth_info_required,
+                        *printer_uri,
+                        *session_path,
+                        *collection_path;
+  GDBusProxy            *item_proxy;
+  guint                  prompt_subscription;
+} SecretsServiceData;
 
 /**
  * create_attributes:
@@ -54,12 +60,12 @@ typedef struct
  * Returns: A GVariant dictionary of string pairs or NULL on error.
  */
 static GVariant *
-create_attributes (const gchar *printer_uri,
-                   gchar **additional_attrs,
-                   gchar **additional_labels)
+create_attributes (const gchar  *printer_uri,
+                   gchar       **additional_attrs,
+                   gchar       **additional_labels)
 {
   GVariantBuilder *attr_builder = NULL;
-  GVariant *ret = NULL;
+  GVariant        *ret = NULL;
 
   if (printer_uri == NULL)
     {
@@ -72,7 +78,7 @@ create_attributes (const gchar *printer_uri,
   /* The printer uri is the main identifying part */
   g_variant_builder_add (attr_builder, "{ss}", "uri", printer_uri);
 
-  if (additional_labels)
+  if (additional_labels != NULL)
     {
       int i;
       for (i = 0; additional_labels[i] != NULL; i++)
@@ -90,22 +96,21 @@ create_attributes (const gchar *printer_uri,
 }
 
 static void
-get_secret_cb (GObject *source_object,
+get_secret_cb (GObject      *source_object,
                GAsyncResult *res,
-               gpointer user_data)
+               gpointer      user_data)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
-  GError               *error = NULL;
-  GVariant             *output,
-                       *attributes;
-  gchar               **auth_info = NULL,
-                       *key = NULL,
-                       *value = NULL;
-  GVariantIter *iter = NULL;
-  guint                i,
-                       j;
-  gint                 pw_field = -1;
+  GTask              *task;
+  SecretsServiceData *task_data;
+  GError             *error = NULL;
+  GVariant           *output,
+                     *attributes;
+  gchar             **auth_info = NULL,
+                     *key = NULL,
+                     *value = NULL;
+  GVariantIter       *iter = NULL;
+  guint               i;
+  gint                pw_field = -1;
 
   task = user_data;
   task_data = g_task_get_task_data (task);
@@ -133,32 +138,32 @@ get_secret_cb (GObject *source_object,
   g_variant_get (attributes, "a{ss}", &iter);
 
   auth_info = g_new0 (gchar *,
-                      g_strv_length (task_data->request->auth_info_required) + 1);
+                      g_strv_length (task_data->auth_info_required) + 1);
 
   while (g_variant_iter_loop (iter, "{ss}", &key, &value))
     {
       /* Match attributes with required auth info */
-      for (i = 0; task_data->request->auth_info_required[i] != NULL; i++)
+      for (i = 0; task_data->auth_info_required[i] != NULL; i++)
         {
           if ((strcmp (key, "user") == 0 ||
                strcmp (key, "username") == 0) &&
-              strcmp (task_data->request->auth_info_required[i],
+              strcmp (task_data->auth_info_required[i],
                       "username") == 0)
             {
               auth_info[i] = g_strdup (value);
             }
           else if (strcmp (key, "domain") == 0 &&
-              strcmp (task_data->request->auth_info_required[i], "domain") == 0)
+                   strcmp (task_data->auth_info_required[i], "domain") == 0)
             {
               auth_info[i] = g_strdup (value);
             }
           else if ((strcmp (key, "hostname") == 0 ||
-               strcmp (key, "server") == 0 ) &&
-              strcmp (task_data->request->auth_info_required[i], "hostname") == 0)
+                    strcmp (key, "server") == 0 ) &&
+                   strcmp (task_data->auth_info_required[i], "hostname") == 0)
             {
               auth_info[i] = g_strdup (value);
             }
-          else if (strcmp (task_data->request->auth_info_required[i], "password") == 0)
+          else if (strcmp (task_data->auth_info_required[i], "password") == 0)
             {
               pw_field = i;
             }
@@ -167,7 +172,7 @@ get_secret_cb (GObject *source_object,
 
   if (pw_field == -1)
     {
-      /* should not happen...*/
+      /* should not happen... */
       GTK_NOTE (PRINTING, g_print ("No password required?.\n"));
       g_variant_unref (output);
       goto fail;
@@ -184,6 +189,8 @@ get_secret_cb (GObject *source_object,
       if (secret == NULL || g_variant_n_children (secret) != 4)
         {
           GTK_NOTE (PRINTING, g_print ("Get secret response invalid.\n"));
+          if (secret != NULL)
+            g_variant_unref (secret);
           goto fail;
         }
       s_value = g_variant_get_child_value (secret, 2);
@@ -193,24 +200,24 @@ get_secret_cb (GObject *source_object,
 
       g_variant_unref (secret);
 
-      if (ba_passwd == NULL || strlen (ba_passwd) > len + 1)
+      if (ba_passwd == NULL)
         {
           GTK_NOTE (PRINTING, g_print ("Invalid secret.\n"));
           g_variant_unref (s_value);
           goto fail;
         }
 
-      auth_info[pw_field] = g_strdup (ba_passwd);
+      auth_info[pw_field] = g_strndup (ba_passwd, len);
       g_variant_unref (s_value);
     }
 
-  for (i = 0; task_data->request->auth_info_required[i] != NULL; i++)
+  for (i = 0; task_data->auth_info_required[i] != NULL; i++)
     {
       if (auth_info[i] == NULL)
         {
-          /* Error out we did not find everything*/
+          /* Error out we did not find everything */
           GTK_NOTE (PRINTING, g_print ("Failed to lookup required attribute: %s.\n",
-                                       task_data->request->auth_info_required[i]));
+                                       task_data->auth_info_required[i]));
           goto fail;
         }
     }
@@ -221,26 +228,19 @@ get_secret_cb (GObject *source_object,
 fail:
   /* Error out */
   GTK_NOTE (PRINTING, g_print ("Failed to lookup secret.\n"));
-  for (j = 0; j < g_strv_length (task_data->request->auth_info_required); j++)
-    {
-      /* Not all fields of auth_info are neccessarily written so we can not
-         use strfreev here */
-      g_free (auth_info[j]);
-    }
-  g_free (auth_info);
+  g_strfreev (auth_info);
   g_task_return_pointer (task, NULL, NULL);
-  return;
 }
 
 static void
-create_item_cb (GObject *source_object,
+create_item_cb (GObject      *source_object,
                 GAsyncResult *res,
-                gpointer user_data)
+                gpointer      user_data)
 {
-  GTask                *task;
-  GError               *error = NULL;
-  GVariant             *output;
-  gchar                *item = NULL;
+  GTask    *task;
+  GError   *error = NULL;
+  GVariant *output;
+  gchar    *item = NULL;
 
   task = user_data;
 
@@ -254,35 +254,34 @@ create_item_cb (GObject *source_object,
     }
 
   g_variant_get (output, "(&o&o)", &item, NULL);
-  if (item && strlen (item) > 1)
+  if (item != NULL && strlen (item) > 1)
     {
       GTK_NOTE (PRINTING, g_print ("Successfully stored auth info.\n"));
       g_task_return_pointer (task, NULL, NULL);
       return;
     }
   g_variant_unref (output);
-
 }
 
 static void
 do_store_auth_info (GTask *task)
 {
-  GVariant              *attributes = NULL,
-                        *properties = NULL,
-                        *secret = NULL;
-  gchar                **additional_attrs = NULL,
-                       **additional_labels = NULL,
-                        *password = NULL;
-  secrets_service_data  *task_data = g_task_get_task_data (task);
-  guint                  i,
-                         length,
-                         additional_count = 0;
-  GVariantBuilder       *prop_builder = NULL;
+  GVariant            *attributes = NULL,
+                      *properties = NULL,
+                      *secret = NULL;
+  gchar              **additional_attrs = NULL,
+                     **additional_labels = NULL,
+                      *password = NULL;
+  SecretsServiceData  *task_data = g_task_get_task_data (task);
+  guint                i,
+                       length,
+                       additional_count = 0;
+  GVariantBuilder     *prop_builder = NULL;
 
   length = g_strv_length (task_data->auth_info_labels);
 
-  additional_attrs = g_new0 (gchar*, length + 1);
-  additional_labels = g_new0 (gchar*, length + 1);
+  additional_attrs = g_new0 (gchar *, length + 1);
+  additional_labels = g_new0 (gchar *, length + 1);
   /* The labels user and server are chosen to be compatible with
      the attributes used by system-config-printer */
   for (i = 0; task_data->auth_info_labels[i] != NULL; i++)
@@ -348,28 +347,27 @@ do_store_auth_info (GTask *task)
                                          properties,
                                          secret,
                                          TRUE),
-                          NULL,
+                          G_VARIANT_TYPE ("(oo)"),
                           G_DBUS_CALL_FLAGS_NONE,
                           SECRETS_TIMEOUT,
                           g_task_get_cancellable (task),
                           create_item_cb,
                           task);
-  return;
 }
 
 static void
 prompt_completed_cb (GDBusConnection *connection,
-                     const gchar *sender_name,
-                     const gchar *object_path,
-                     const gchar *interface_name,
-                     const gchar *signal_name,
-                     GVariant *parameters,
-                     gpointer user_data)
+                     const gchar     *sender_name,
+                     const gchar     *object_path,
+                     const gchar     *interface_name,
+                     const gchar     *signal_name,
+                     GVariant        *parameters,
+                     gpointer         user_data)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
-  GVariant             *dismissed;
-  gboolean             is_dismissed = TRUE;
+  GTask              *task;
+  SecretsServiceData *task_data;
+  GVariant           *dismissed;
+  gboolean            is_dismissed = TRUE;
 
   task = user_data;
   task_data = g_task_get_task_data (task);
@@ -398,32 +396,35 @@ prompt_completed_cb (GDBusConnection *connection,
     }
 
   /* Prompt successfull, proceed to get or store secret */
-  if (task_data->store_info)
+  switch (task_data->action)
     {
-      do_store_auth_info (task);
-      return;
+      case SECRETS_SERVICE_ACTION_STORE:
+        do_store_auth_info (task);
+        break;
+
+      case SECRETS_SERVICE_ACTION_QUERY:
+        g_dbus_proxy_call (task_data->item_proxy,
+                           "GetSecret",
+                           g_variant_new ("(o)",
+                                          task_data->session_path),
+                           G_DBUS_CALL_FLAGS_NONE,
+                           SECRETS_TIMEOUT,
+                           g_task_get_cancellable (task),
+                           get_secret_cb,
+                           task);
+        break;
     }
-
-  g_dbus_proxy_call (task_data->item_proxy,
-                     "GetSecret",
-                     g_variant_new ("(o)",
-                                    task_data->session_path),
-                     G_DBUS_CALL_FLAGS_NONE,
-                     SECRETS_TIMEOUT,
-                     g_task_get_cancellable (task),
-                     get_secret_cb,
-                     task);
 }
 
 static void
-prompt_cb (GObject *source_object,
+prompt_cb (GObject      *source_object,
            GAsyncResult *res,
-           gpointer user_data)
+           gpointer      user_data)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
-  GError               *error = NULL;
-  GVariant             *output;
+  GTask              *task;
+  SecretsServiceData *task_data;
+  GError             *error = NULL;
+  GVariant           *output;
 
   task = user_data;
   task_data = g_task_get_task_data (task);
@@ -451,19 +452,18 @@ prompt_cb (GObject *source_object,
                                         prompt_completed_cb,
                                         task,
                                         NULL);
-  return;
 }
 
 static void
-unlock_collection_cb (GObject *source_object,
+unlock_collection_cb (GObject      *source_object,
                       GAsyncResult *res,
-                      gpointer user_data)
+                      gpointer      user_data)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
-  GError               *error = NULL;
-  GVariant             *output;
-  const gchar          *prompt_path;
+  GTask              *task;
+  SecretsServiceData *task_data;
+  GError             *error = NULL;
+  GVariant           *output;
+  const gchar        *prompt_path;
 
   task = user_data;
   task_data = g_task_get_task_data (task);
@@ -479,7 +479,7 @@ unlock_collection_cb (GObject *source_object,
 
   g_variant_get (output, "(@ao&o)", NULL, &prompt_path);
 
-  if (prompt_path != NULL && strlen (prompt_path) > 2)
+  if (prompt_path != NULL && strlen (prompt_path) > 1)
     {
       g_dbus_connection_call (task_data->dbus_connection,
                               SECRETS_BUS,
@@ -487,47 +487,50 @@ unlock_collection_cb (GObject *source_object,
                               SECRETS_IFACE ("Prompt"),
                               "Prompt",
                               g_variant_new ("(s)", "0"),
-                              NULL,
+                              G_VARIANT_TYPE ("()"),
                               G_DBUS_CALL_FLAGS_NONE,
                               SECRETS_TIMEOUT,
                               g_task_get_cancellable (task),
                               prompt_cb,
                               task);
     }
-  else if (task_data->store_info)
-    {
-      do_store_auth_info (task);
-    }
   else
     {
-      /* Prompt successfull proceed to get secret */
-      g_dbus_proxy_call (task_data->item_proxy,
-                         "GetSecret",
-                         g_variant_new ("(o)",
-                                        task_data->session_path),
-                         G_DBUS_CALL_FLAGS_NONE,
-                         SECRETS_TIMEOUT,
-                         g_task_get_cancellable (task),
-                         get_secret_cb,
-                         task);
+      switch (task_data->action)
+        {
+          case SECRETS_SERVICE_ACTION_STORE:
+            do_store_auth_info (task);
+            break;
+
+          case SECRETS_SERVICE_ACTION_QUERY:
+            /* Prompt successfull proceed to get secret */
+            g_dbus_proxy_call (task_data->item_proxy,
+                               "GetSecret",
+                               g_variant_new ("(o)",
+                                              task_data->session_path),
+                               G_DBUS_CALL_FLAGS_NONE,
+                               SECRETS_TIMEOUT,
+                               g_task_get_cancellable (task),
+                               get_secret_cb,
+                               task);
+            break;
+        }
     }
   g_variant_unref (output);
-
-  return;
 }
 
 static void
-unlock_read_alias_cb (GObject *source_object,
+unlock_read_alias_cb (GObject      *source_object,
                       GAsyncResult *res,
-                      gpointer user_data)
+                      gpointer      user_data)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
-  GError               *error = NULL;
-  GVariant             *output,
-                       *subresult;
-  gsize                 path_len = 0;
-  const gchar          *collection_path;
+  GTask              *task;
+  SecretsServiceData *task_data;
+  GError             *error = NULL;
+  GVariant           *output,
+                     *subresult;
+  gsize               path_len = 0;
+  const gchar        *collection_path;
 
   task = user_data;
   task_data = g_task_get_task_data (task);
@@ -553,43 +556,40 @@ unlock_read_alias_cb (GObject *source_object,
 
   collection_path = g_variant_get_string (subresult, &path_len);
 
-    {
-      const gchar * const to_unlock[] = {
-          collection_path,
-          NULL
-      };
+  const gchar * const to_unlock[] =
+  {
+    collection_path, NULL
+  };
 
-      task_data->collection_path = g_strdup (collection_path);
+  task_data->collection_path = g_strdup (collection_path);
 
-      g_dbus_connection_call (task_data->dbus_connection,
-                              SECRETS_BUS,
-                              SECRETS_PATH,
-                              SECRETS_IFACE ("Service"),
-                              "Unlock",
-                              g_variant_new ("(^ao)", to_unlock),
-                              NULL,
-                              G_DBUS_CALL_FLAGS_NONE,
-                              SECRETS_TIMEOUT,
-                              g_task_get_cancellable (task),
-                              unlock_collection_cb,
-                              task);
-    }
+  g_dbus_connection_call (task_data->dbus_connection,
+                          SECRETS_BUS,
+                          SECRETS_PATH,
+                          SECRETS_IFACE ("Service"),
+                          "Unlock",
+                          g_variant_new ("(^ao)", to_unlock),
+                          G_VARIANT_TYPE ("(aoo)"),
+                          G_DBUS_CALL_FLAGS_NONE,
+                          SECRETS_TIMEOUT,
+                          g_task_get_cancellable (task),
+                          unlock_collection_cb,
+                          task);
 
   g_variant_unref (subresult);
-  return;
 }
 
 static void
-item_proxy_cb (GObject *source_object,
+item_proxy_cb (GObject      *source_object,
                GAsyncResult *res,
-               gpointer user_data)
+               gpointer      user_data)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
-  GError               *error = NULL;
-  GDBusProxy           *item_proxy;
-  GVariant             *locked;
-  gboolean             is_locked;
+  GTask              *task;
+  SecretsServiceData *task_data;
+  GError             *error = NULL;
+  GDBusProxy         *item_proxy;
+  GVariant           *locked;
+  gboolean            is_locked;
 
   task = user_data;
   task_data = g_task_get_task_data (task);
@@ -608,7 +608,7 @@ item_proxy_cb (GObject *source_object,
 
   if (locked == NULL)
     {
-      GTK_NOTE (PRINTING, g_print ("Failed to look up locked property on item.\n"));
+      GTK_NOTE (PRINTING, g_print ("Failed to look up \"Locked\" property on item.\n"));
       g_task_return_pointer (task, NULL, NULL);
       return;
     }
@@ -625,7 +625,7 @@ item_proxy_cb (GObject *source_object,
                               SECRETS_IFACE ("Service"),
                               "ReadAlias",
                               g_variant_new ("(s)", "default"),
-                              NULL,
+                              G_VARIANT_TYPE ("(o)"),
                               G_DBUS_CALL_FLAGS_NONE,
                               SECRETS_TIMEOUT,
                               g_task_get_cancellable (task),
@@ -635,35 +635,38 @@ item_proxy_cb (GObject *source_object,
     }
 
   /* Unlocked proceed to get or store secret */
-  if (task_data->store_info)
+  switch (task_data->action)
     {
-      do_store_auth_info (task);
-      return;
+      case SECRETS_SERVICE_ACTION_STORE:
+        do_store_auth_info (task);
+        break;
+
+      case SECRETS_SERVICE_ACTION_QUERY:
+        g_dbus_proxy_call (item_proxy,
+                           "GetSecret",
+                           g_variant_new ("(o)",
+                                          task_data->session_path),
+                           G_DBUS_CALL_FLAGS_NONE,
+                           SECRETS_TIMEOUT,
+                           g_task_get_cancellable (task),
+                           get_secret_cb,
+                           task);
+        break;
     }
-  g_dbus_proxy_call (item_proxy,
-                     "GetSecret",
-                     g_variant_new ("(o)",
-                                    task_data->session_path),
-                     G_DBUS_CALL_FLAGS_NONE,
-                     SECRETS_TIMEOUT,
-                     g_task_get_cancellable (task),
-                     get_secret_cb,
-                     task);
-  return;
 }
 
 static void
-search_items_cb (GObject *source_object,
+search_items_cb (GObject      *source_object,
                  GAsyncResult *res,
-                 gpointer user_data)
+                 gpointer      user_data)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
-  GError               *error = NULL;
-  GVariant             *output;
-  gsize                 array_cnt,
-                        i;
-  gboolean              found_item = FALSE;
+  GTask              *task;
+  SecretsServiceData *task_data;
+  GError             *error = NULL;
+  GVariant           *output;
+  gsize               array_cnt,
+                      i;
+  gboolean            found_item = FALSE;
 
   task = user_data;
   task_data = g_task_get_task_data (task);
@@ -681,8 +684,8 @@ search_items_cb (GObject *source_object,
 
   for (i = 0; i < array_cnt; i++)
     {
-      GVariant *const item_paths = g_variant_get_child_value (output, i);
-      const gchar **items = NULL;
+      GVariant * const   item_paths = g_variant_get_child_value (output, i);
+      const gchar      **items = NULL;
 
       if (item_paths == NULL)
         {
@@ -696,6 +699,7 @@ search_items_cb (GObject *source_object,
       if (*items == NULL)
         {
           g_variant_unref (item_paths);
+          g_free ((gpointer) items);
           continue;
         }
 
@@ -725,16 +729,15 @@ search_items_cb (GObject *source_object,
 }
 
 static void
-open_session_cb (GObject *source_object,
+open_session_cb (GObject      *source_object,
                  GAsyncResult *res,
-                 gpointer user_data)
+                 gpointer      user_data)
 {
-  GTask                *task;
-  GVariant             *output,
-                       *session_variant;
-  secrets_service_data *task_data;
-  const gchar          *session_path;
-  GError               *error = NULL;
+  GTask              *task;
+  GVariant           *output,
+                     *session_variant;
+  SecretsServiceData *task_data;
+  GError             *error = NULL;
 
   task = user_data;
   task_data = g_task_get_task_data (task);
@@ -758,9 +761,9 @@ open_session_cb (GObject *source_object,
       return;
     }
 
-  session_path = g_variant_get_string (session_variant, NULL);
+  task_data->session_path = g_variant_dup_string (session_variant, NULL);
 
-  if (session_path == NULL)
+  if (task_data->session_path == NULL)
     {
       GTK_NOTE (PRINTING, g_print ("Invalid session path string value.\n"));
       g_variant_unref (session_variant);
@@ -769,56 +772,57 @@ open_session_cb (GObject *source_object,
       return;
     }
 
-  task_data->session_path = g_strdup (session_path);
-
   g_variant_unref (session_variant);
   g_variant_unref (output);
 
-  if (!task_data->store_info)
+  switch (task_data->action)
     {
-      /* Search for the secret item */
-      GVariant    *secrets_attrs;
-      const gchar *printer_uri;
+      case SECRETS_SERVICE_ACTION_QUERY:
+        {
+          /* Search for the secret item */
+          GVariant *secrets_attrs;
 
-      printer_uri = gtk_cups_request_ipp_get_string (task_data->request,
-                                                     IPP_TAG_URI,
-                                                     "printer-uri");
+          secrets_attrs = create_attributes (task_data->printer_uri, NULL, NULL);
+          if (secrets_attrs == NULL)
+            {
+              GTK_NOTE (PRINTING, g_print ("Failed to create attributes.\n"));
+              g_task_return_pointer (task, NULL, NULL);
+              return;
+            }
 
-      secrets_attrs = create_attributes (printer_uri, NULL, NULL);
-      if (secrets_attrs == NULL)
-        {
-          GTK_NOTE (PRINTING, g_print ("Failed to create attributes.\n"));
-          g_task_return_pointer (task, NULL, NULL);
-          return;
+          g_dbus_connection_call (task_data->dbus_connection,
+                                  SECRETS_BUS,
+                                  SECRETS_PATH,
+                                  SECRETS_IFACE ("Service"),
+                                  "SearchItems",
+                                  g_variant_new ("(@a{ss})", secrets_attrs),
+                                  G_VARIANT_TYPE ("(aoao)"),
+                                  G_DBUS_CALL_FLAGS_NONE,
+                                  SECRETS_TIMEOUT,
+                                  g_task_get_cancellable (task),
+                                  search_items_cb,
+                                  task);
+          break;
         }
 
-      g_dbus_connection_call (task_data->dbus_connection,
-                              SECRETS_BUS,
-                              SECRETS_PATH,
-                              SECRETS_IFACE ("Service"),
-                              "SearchItems",
-                              g_variant_new ("(@a{ss})", secrets_attrs),
-                              NULL,
-                              G_DBUS_CALL_FLAGS_NONE,
-                              SECRETS_TIMEOUT,
-                              g_task_get_cancellable (task),
-                              search_items_cb,
-                              task);
-      return;
+      case SECRETS_SERVICE_ACTION_STORE:
+        {
+          /* Look up / unlock the default collection for storing */
+          g_dbus_connection_call (task_data->dbus_connection,
+                                  SECRETS_BUS,
+                                  SECRETS_PATH,
+                                  SECRETS_IFACE ("Service"),
+                                  "ReadAlias",
+                                  g_variant_new ("(s)", "default"),
+                                  G_VARIANT_TYPE ("(o)"),
+                                  G_DBUS_CALL_FLAGS_NONE,
+                                  SECRETS_TIMEOUT,
+                                  g_task_get_cancellable (task),
+                                  unlock_read_alias_cb,
+                                  task);
+          break;
+        }
     }
-  /* Look up / unlock the default collection for storing */
-  g_dbus_connection_call (task_data->dbus_connection,
-                          SECRETS_BUS,
-                          SECRETS_PATH,
-                          SECRETS_IFACE ("Service"),
-                          "ReadAlias",
-                          g_variant_new ("(s)", "default"),
-                          NULL,
-                          G_DBUS_CALL_FLAGS_NONE,
-                          SECRETS_TIMEOUT,
-                          g_task_get_cancellable (task),
-                          unlock_read_alias_cb,
-                          task);
 }
 
 static void
@@ -826,31 +830,29 @@ get_connection_cb (GObject      *source_object,
                    GAsyncResult *res,
                    gpointer      user_data)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
-  GDBusConnection      *dbus_connection;
-  GError               *error = NULL;
+  GTask              *task;
+  SecretsServiceData *task_data;
+  GError             *error = NULL;
 
   task = user_data;
   task_data = g_task_get_task_data (task);
 
-  dbus_connection = g_bus_get_finish (res, &error);
-  if (dbus_connection == NULL)
+  task_data->dbus_connection = g_bus_get_finish (res, &error);
+  if (task_data->dbus_connection == NULL)
     {
       g_task_return_error (task, error);
       return;
     }
-  task_data->dbus_connection = dbus_connection;
 
   /* Now open a session */
-  g_dbus_connection_call (dbus_connection,
+  g_dbus_connection_call (task_data->dbus_connection,
                           SECRETS_BUS,
                           SECRETS_PATH,
                           SECRETS_IFACE ("Service"),
                           "OpenSession",
                           g_variant_new ("(sv)", "plain",
                                          g_variant_new_string ("")),
-                          NULL,
+                          G_VARIANT_TYPE ("(vo)"),
                           G_DBUS_CALL_FLAGS_NONE,
                           SECRETS_TIMEOUT,
                           g_task_get_cancellable (task),
@@ -871,7 +873,7 @@ get_connection_cb (GObject      *source_object,
 guint
 gtk_cups_secrets_service_watch (GBusNameAppearedCallback appeared,
                                 GBusNameVanishedCallback vanished,
-                                gpointer user_data)
+                                gpointer                 user_data)
 {
   return g_bus_watch_name (G_BUS_TYPE_SESSION,
                            SECRETS_BUS,
@@ -885,23 +887,13 @@ gtk_cups_secrets_service_watch (GBusNameAppearedCallback appeared,
 void
 cleanup_task_data (gpointer data)
 {
-  gint                  i;
-  secrets_service_data *task_data = data;
+  gint                i;
+  SecretsServiceData *task_data = data;
 
-  if (task_data->collection_path != NULL)
-    {
-      g_free (task_data->collection_path);
-    }
-
-  if (task_data->auth_info_labels != NULL)
-    {
-      g_strfreev (task_data->auth_info_labels);
-    }
-
-  if (task_data->printer_uri != NULL)
-    {
-      g_free (task_data->printer_uri);
-    }
+  g_free (task_data->collection_path);
+  g_strfreev (task_data->auth_info_labels);
+  g_strfreev (task_data->auth_info_required);
+  g_free (task_data->printer_uri);
 
   if (task_data->auth_info != NULL)
     {
@@ -910,7 +902,7 @@ cleanup_task_data (gpointer data)
           memset (task_data->auth_info[i], 0, strlen (task_data->auth_info[i]));
           g_clear_pointer (&task_data->auth_info[i], g_free);
         }
-      g_clear_pointer (task_data->auth_info, g_free);
+      g_clear_pointer (&task_data->auth_info, g_free);
     }
 
   if (task_data->prompt_subscription != 0)
@@ -928,7 +920,7 @@ cleanup_task_data (gpointer data)
                               SECRETS_IFACE ("Session"),
                               "Close",
                               NULL,
-                              NULL,
+                              G_VARIANT_TYPE ("()"),
                               G_DBUS_CALL_FLAGS_NONE,
                               SECRETS_TIMEOUT,
                               NULL,
@@ -947,7 +939,8 @@ cleanup_task_data (gpointer data)
  * @cancellable: Cancellable to cancel this task
  * @callback: Callback to call once the query is finished
  * @user_data: The user_data passed to the callback
- * @request: The request for which the auth info should be looked up.
+ * @printer_uri: URI of the printer
+ * @auth_info_required: Info required for authentication
  *
  * Checks if a secrets service as described by the secrets-service standard
  * is available and if so it tries to find the authentication info in the
@@ -961,18 +954,20 @@ cleanup_task_data (gpointer data)
  * of the used API.
  */
 void
-gtk_cups_secrets_service_query_task (gpointer source_object,
-                                     GCancellable *cancellable,
-                                     GAsyncReadyCallback callback,
-                                     gpointer user_data,
-                                     GtkCupsRequest *request)
+gtk_cups_secrets_service_query_task (gpointer              source_object,
+                                     GCancellable         *cancellable,
+                                     GAsyncReadyCallback   callback,
+                                     gpointer              user_data,
+                                     const gchar          *printer_uri,
+                                     gchar               **auth_info_required)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
+  GTask              *task;
+  SecretsServiceData *task_data;
 
-  task_data = g_new0 (secrets_service_data, 1);
-  task_data->store_info = FALSE;
-  task_data->request = request;
+  task_data = g_new0 (SecretsServiceData, 1);
+  task_data->action = SECRETS_SERVICE_ACTION_QUERY;
+  task_data->printer_uri = g_strdup (printer_uri);
+  task_data->auth_info_required = g_strdupv (auth_info_required);
 
   task = g_task_new (source_object, cancellable, callback, user_data);
 
@@ -980,15 +975,14 @@ gtk_cups_secrets_service_query_task (gpointer source_object,
 
   g_bus_get (G_BUS_TYPE_SESSION, cancellable,
              get_connection_cb, task);
-  return;
 }
 
 static void
-store_done_cb (GObject *source_object,
+store_done_cb (GObject      *source_object,
                GAsyncResult *res,
-               gpointer user_data)
+               gpointer      user_data)
 {
-  GTask *task = (GTask *) res;
+  GTask  *task = (GTask *) res;
   GError *error = NULL;
 
   g_task_propagate_pointer (task, &error);
@@ -1003,7 +997,6 @@ store_done_cb (GObject *source_object,
   g_object_unref (task);
   GTK_NOTE (PRINTING,
             g_print ("gtk_cups_secrets_service_store finished.\n"));
-  return;
 }
 
 /**
@@ -1013,16 +1006,14 @@ store_done_cb (GObject *source_object,
  * @printer_uri: URI of the printer
  *
  * Tries to store the auth_info in a secrets service.
- *
  */
 void
-gtk_cups_secrets_service_store (gchar **auth_info,
-                                gchar **auth_info_labels,
-                                const gchar* printer_uri)
+gtk_cups_secrets_service_store (gchar       **auth_info,
+                                gchar       **auth_info_labels,
+                                const gchar  *printer_uri)
 {
-  GTask                *task;
-  secrets_service_data *task_data;
-  guint                 i;
+  GTask              *task;
+  SecretsServiceData *task_data;
 
   if (auth_info == NULL || auth_info_labels == NULL || printer_uri == NULL)
     {
@@ -1031,22 +1022,11 @@ gtk_cups_secrets_service_store (gchar **auth_info,
       return;
     }
 
-  task_data = g_new0 (secrets_service_data, 1);
-  task_data->store_info = TRUE;
+  task_data = g_new0 (SecretsServiceData, 1);
+  task_data->action = SECRETS_SERVICE_ACTION_STORE;
   task_data->printer_uri = g_strdup (printer_uri);
-  task_data->auth_info = g_new0 (gchar *, g_strv_length (auth_info) + 1);
-  task_data->auth_info_labels = g_new0 (gchar *, g_strv_length (auth_info_labels) + 1);
-
-  /* Copy the values to store for the task */
-  for (i = 0; auth_info[i] != NULL; i++)
-    {
-      task_data->auth_info[i] = g_strdup (auth_info[i]);
-    }
-
-  for (i = 0; auth_info[i] != NULL; i++)
-    {
-      task_data->auth_info_labels[i] = g_strdup (auth_info_labels[i]);
-    }
+  task_data->auth_info = g_strdupv (auth_info);
+  task_data->auth_info_labels = g_strdupv (auth_info_labels);
 
   task = g_task_new (NULL, NULL, store_done_cb, NULL);
 
@@ -1054,5 +1034,4 @@ gtk_cups_secrets_service_store (gchar **auth_info,
 
   g_bus_get (G_BUS_TYPE_SESSION, NULL,
              get_connection_cb, task);
-  return;
 }
diff --git a/modules/printbackends/cups/gtkcupssecretsutils.h b/modules/printbackends/cups/gtkcupssecretsutils.h
index ef67a96..1a0424a 100644
--- a/modules/printbackends/cups/gtkcupssecretsutils.h
+++ b/modules/printbackends/cups/gtkcupssecretsutils.h
@@ -23,17 +23,18 @@
 
 G_BEGIN_DECLS
 
-void gtk_cups_secrets_service_query_task (gpointer            source_object,
-                                          GCancellable       *cancellable,
-                                          GAsyncReadyCallback callback,
-                                          gpointer            user_data,
-                                          GtkCupsRequest     *request);
-guint gtk_cups_secrets_service_watch (GBusNameAppearedCallback appeared,
-                                      GBusNameVanishedCallback vanished,
-                                      gpointer                 user_data);
-void gtk_cups_secrets_service_store (gchar **auth_info,
-                                     gchar **auth_info_labels,
-                                     const gchar *printer_uri);
+void  gtk_cups_secrets_service_query_task (gpointer                   source_object,
+                                           GCancellable              *cancellable,
+                                           GAsyncReadyCallback        callback,
+                                           gpointer                   user_data,
+                                           const gchar               *printer_uri,
+                                           gchar                    **auth_info_required);
+guint gtk_cups_secrets_service_watch      (GBusNameAppearedCallback   appeared,
+                                           GBusNameVanishedCallback   vanished,
+                                           gpointer                   user_data);
+void  gtk_cups_secrets_service_store      (gchar                    **auth_info,
+                                           gchar                    **auth_info_labels,
+                                           const gchar               *printer_uri);
 
 G_END_DECLS
 
diff --git a/modules/printbackends/cups/gtkprintbackendcups.c b/modules/printbackends/cups/gtkprintbackendcups.c
index b54ae9a..a269c4c 100644
--- a/modules/printbackends/cups/gtkprintbackendcups.c
+++ b/modules/printbackends/cups/gtkprintbackendcups.c
@@ -799,8 +799,8 @@ gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups)
 
   cups_get_local_default_printer (backend_cups);
 
-  backend_cups->secrets_service_cancellable = NULL;
   backend_cups->secrets_service_available = FALSE;
+  backend_cups->secrets_service_cancellable = g_cancellable_new ();
   backend_cups->secrets_service_watch_id =
     gtk_cups_secrets_service_watch (secrets_service_appeared_cb,
                                     secrets_service_vanished_cb,
@@ -927,7 +927,7 @@ static void
 gtk_print_backend_cups_set_password (GtkPrintBackend  *backend,
                                      gchar           **auth_info_required,
                                      gchar           **auth_info,
-                                     gboolean        store_auth_info)
+                                     gboolean          store_auth_info)
 {
   GtkPrintBackendCups *cups_backend = GTK_PRINT_BACKEND_CUPS (backend);
   GList *l;
@@ -982,7 +982,7 @@ gtk_print_backend_cups_set_password (GtkPrintBackend  *backend,
           /* Save the password if the user requested it */
           if (password != NULL && store_auth_info)
             {
-              const gchar * printer_uri =
+              const gchar *printer_uri =
                   gtk_cups_request_ipp_get_string (dispatch->request,
                                                    IPP_TAG_URI,
                                                    "printer-uri");
@@ -1224,9 +1224,9 @@ check_auth_info (gpointer user_data)
 }
 
 static void
-lookup_auth_info_cb (GObject *source_object,
+lookup_auth_info_cb (GObject      *source_object,
                      GAsyncResult *res,
-                     gpointer user_data)
+                     gpointer      user_data)
 {
   GTask                      *task;
   GtkPrintCupsDispatchWatch  *dispatch;
@@ -1268,7 +1268,6 @@ lookup_auth_info_cb (GObject *source_object,
   g_clear_pointer (auth_info, g_free);
 
   g_object_unref (task);
-  return;
 }
 
 static void
@@ -1278,6 +1277,7 @@ lookup_auth_info (gpointer user_data)
   gsize                       length,
                               i;
   gboolean                    need_secret_auth_info = FALSE;
+  const gchar                *printer_uri;
 
   dispatch = user_data;
 
@@ -1295,19 +1295,24 @@ lookup_auth_info (gpointer user_data)
         }
     }
 
+  g_idle_add (check_auth_info, user_data);
+
   if (dispatch->backend->secrets_service_available && need_secret_auth_info)
     {
       dispatch->backend->authentication_lock = TRUE;
+      printer_uri = gtk_cups_request_ipp_get_string (dispatch->request,
+                                                     IPP_TAG_URI,
+                                                     "printer-uri");
       gtk_cups_secrets_service_query_task (dispatch->backend,
                                            dispatch->backend->secrets_service_cancellable,
                                            lookup_auth_info_cb,
                                            dispatch,
-                                           dispatch->request);
+                                           printer_uri,
+                                           dispatch->request->auth_info_required);
       return;
     }
 
   request_auth_info (user_data);
-  return;
 }
 
 static gboolean
@@ -1400,8 +1405,6 @@ request_auth_info (gpointer user_data)
   g_free (printer_name);
   g_free (prompt);
 
-  g_idle_add (check_auth_info, user_data);
-
   return FALSE;
 }
 
@@ -6053,28 +6056,21 @@ cups_printer_get_capabilities (GtkPrinter *printer)
 
 static void
 secrets_service_appeared_cb (GDBusConnection *connection,
-                             const gchar *name,
-                             const gchar *name_owner,
-                             gpointer user_data)
+                             const gchar     *name,
+                             const gchar     *name_owner,
+                             gpointer         user_data)
 {
   GtkPrintBackendCups *backend = GTK_PRINT_BACKEND_CUPS (user_data);
+
   backend->secrets_service_available = TRUE;
-  if (backend->secrets_service_cancellable == NULL)
-    {
-      backend->secrets_service_cancellable = g_cancellable_new ();
-    }
 }
 
 static void
 secrets_service_vanished_cb (GDBusConnection *connection,
-                             const gchar *name,
-                             gpointer user_data)
+                             const gchar     *name,
+                             gpointer         user_data)
 {
   GtkPrintBackendCups *backend = GTK_PRINT_BACKEND_CUPS (user_data);
 
   backend->secrets_service_available = FALSE;
-  if (backend->secrets_service_cancellable != NULL)
-    {
-      g_clear_object (&backend->secrets_service_cancellable);
-    }
 }
