diff --git a/core/artifacts_versions.c b/core/artifacts_versions.c
index 7d1d035..cba45b7 100644
--- a/core/artifacts_versions.c
+++ b/core/artifacts_versions.c
@@ -149,7 +149,7 @@ void get_sw_versions(char *cfgname, struct swupdate_cfg *sw)
 }
 #else
 
-void get_sw_versions(char __attribute__ ((__unused__)) *cfgname,
+void get_sw_versions(swupdate_cfg_handle  __attribute__ ((__unused__))*handle,
 			struct swupdate_cfg *sw)
 {
 	read_sw_version_file(sw);
diff --git a/core/swupdate.c b/core/swupdate.c
index 6548d06..37eda4c 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -547,11 +547,16 @@ int main(int argc, char **argv)
 
 	/* Load configuration file */
 	if (cfgfname != NULL) {
+		swupdate_cfg_handle handle;
+		int ret = swupdate_cfg_init(&handle, cfgfname);
+
 		/*
 		 * 'globals' section is mandatory if configuration file is specified.
 		 */
-		int ret = read_module_settings(cfgfname, "globals",
-					       read_globals_settings, &swcfg);
+		if (ret == 0) {
+			ret = swupdate_cfg_read_module_settings(&handle, "globals",
+					read_globals_settings, &swcfg);
+		}
 		if (ret != 0) {
 			/*
 			 * Exit on -ENODATA or -EINVAL errors.
@@ -560,6 +565,7 @@ int main(int argc, char **argv)
 			    "Error parsing configuration file: %s, exiting.\n",
 			    ret == -ENODATA ? "'globals' section missing"
 					    : "cannot read");
+			swupdate_cfg_destroy(&handle);
 			exit(EXIT_FAILURE);
 		}
 
@@ -569,11 +575,13 @@ int main(int argc, char **argv)
 		 * The following sections are optional, hence -ENODATA error code is
 		 * ignored if the section is not found. -EINVAL will not happen here.
 		 */
-		(void)read_module_settings(cfgfname, "logcolors",
+		(void)swupdate_cfg_read_module_settings(&handle, "logcolors",
 					   read_console_settings, &swcfg);
 
-		(void)read_module_settings(cfgfname, "processes",
+		(void)swupdate_cfg_read_module_settings(&handle, "processes",
 					   read_processes_settings, &swcfg);
+
+		swupdate_cfg_destroy(&handle);
 	}
 
 	/*
diff --git a/corelib/swupdate_settings.c b/corelib/swupdate_settings.c
index de7f331..f06ecf7 100644
--- a/corelib/swupdate_settings.c
+++ b/corelib/swupdate_settings.c
@@ -10,6 +10,7 @@
  * starting swupdate with a long list of parameters.
  */
 
+#include <libconfig.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -53,6 +54,9 @@ static int read_settings_file(config_t *cfg, const char *filename)
 {
 	int ret;
 
+ 	if (!filename)
+		return -EINVAL;
+
 	TRACE("Reading config file %s", filename);
 	ret = config_read_file(cfg, filename);
 	if (ret != CONFIG_TRUE) {
@@ -69,35 +73,15 @@ static int read_settings_file(config_t *cfg, const char *filename)
 
 int read_module_settings(const char *filename, const char *module, settings_callback fcn, void *data)
 {
-	config_t cfg;
-	config_setting_t *elem;
-
-	if (!fcn || !filename)
-		return -EINVAL;
-
-	memset(&cfg, 0, sizeof(cfg));
-	config_init(&cfg);
-
-	if (read_settings_file(&cfg, filename) != CONFIG_TRUE) {
-		config_destroy(&cfg);
+	swupdate_cfg_handle handle;
+	int ret = swupdate_cfg_init(&handle, filename);
+	if (ret == 0) {
+		ret = swupdate_cfg_read_module_settings(&handle, module, fcn, data);
+	} else {
 		ERROR("Error reading configuration file, skipping....");
-		return -EINVAL;
-	}
-
-	elem = find_settings_node(&cfg, module);
-
-	if (!elem) {
-		TRACE("No config settings found for module %s", module);
-		config_destroy(&cfg);
-		return -ENODATA;
 	}
-
-	TRACE("Reading config settings for module %s", module);
-	fcn(elem, data);
-
-	config_destroy(&cfg);
-
-	return 0;
+	swupdate_cfg_destroy(&handle);
+	return ret;
 }
 
 static int get_run_as(void *elem, void *data)
@@ -162,3 +146,37 @@ int settings_into_dict(void *settings, void *data)
 
 	return 0;
 }
+
+int swupdate_cfg_init(swupdate_cfg_handle *handle, const char *filename)
+{
+	config_init(&handle->cfg);
+	if (read_settings_file(&handle->cfg, filename) != CONFIG_TRUE) {
+		return -EINVAL;
+	}
+	return 0;
+}
+
+void swupdate_cfg_destroy(swupdate_cfg_handle *handle)
+{
+	config_destroy(&handle->cfg);
+}
+
+int swupdate_cfg_read_module_settings(swupdate_cfg_handle *handle, const char *module, settings_callback fcn, void *data)
+{
+	config_setting_t *elem;
+
+	if (!fcn)
+		return -EINVAL;
+
+	TRACE("Reading config file settings for module %s", module);
+	elem = find_settings_node(&handle->cfg, module);
+
+	if (!elem) {
+		TRACE("No config file settings found for module %s", module);
+		return -ENODATA;
+	}
+
+	fcn(elem, data);
+
+	return 0;
+}
diff --git a/include/parselib.h b/include/parselib.h
index 5cbc255..84a51e2 100644
--- a/include/parselib.h
+++ b/include/parselib.h
@@ -85,8 +85,6 @@ void *get_node_json(json_object *root, const char **nodes);
 #define get_node_json(root, nodes)	(NULL)
 #endif
 
-typedef int (*settings_callback)(void *elem, void *data);
-
 const char *get_field_string(parsertype p, void *e, const char *path);
 void get_field_string_with_size(parsertype p, void *e, const char *path,
 				char *d, size_t n);
diff --git a/include/swupdate_settings.h b/include/swupdate_settings.h
index c3b083d..c8e4f1d 100644
--- a/include/swupdate_settings.h
+++ b/include/swupdate_settings.h
@@ -8,12 +8,29 @@
 #ifndef _SWUPDATE_SETTINGS_H
 #define _SWUPDATE_SETTINGS_H
 
+#include <unistd.h>
+
+typedef int (*settings_callback)(void *elem, void *data);
+
 #ifdef CONFIG_LIBCONFIG
+
+#include <libconfig.h>
+
+typedef struct {
+	config_t cfg;
+} swupdate_cfg_handle;
+
+int swupdate_cfg_init(swupdate_cfg_handle *handle, const char *filename);
+void swupdate_cfg_destroy(swupdate_cfg_handle *handle);
+int swupdate_cfg_read_module_settings(swupdate_cfg_handle *handle, const char *module, settings_callback fcn, void *data);
+
 int read_module_settings(const char *filename, const char *module, settings_callback fcn, void *data);
 int read_settings_user_id(const char *filename, const char *module, uid_t *userid, gid_t *groupid);
 int settings_into_dict(void *settings, void *data);
 #else
-#include <unistd.h>
+
+typedef struct {} swupdate_cfg_handle;
+
 static inline int read_module_settings(const char __attribute__ ((__unused__))*filename,
 		const char __attribute__ ((__unused__)) *module,
 		settings_callback __attribute__ ((__unused__)) fcn,
@@ -40,6 +57,24 @@ static inline int settings_into_dict(void __attribute__ ((__unused__)) *settings
 {
 	return -1;
 }
+
+static inline int swupdate_cfg_init(swupdate_cfg_handle __attribute__ ((__unused__))*handle,
+		const char __attribute__ ((__unused__))*filename)
+{
+	return -1;
+}
+
+static inline void swupdate_cfg_destroy(swupdate_cfg_handle __attribute__ ((__unused__))*handle) {
+	return;
+}
+
+static inline int swupdate_cfg_read_module_settings(swupdate_cfg_handle __attribute__ ((__unused__))*handle,
+		const char __attribute__ ((__unused__))*module,
+		settings_callback __attribute__ ((__unused__))fcn,
+		void __attribute__ ((__unused__))*data) {
+	return -1;
+};
+
 #endif
 
 #endif
