diff --git a/package/gluon-node-info/src/respondd.c b/package/gluon-node-info/src/respondd.c
index d74c69e6cb7bdd1f3f2bafb97e9a10ca99862265..3b0e07dced1017d4c4e498367b658be0a83f67f5 100644
--- a/package/gluon-node-info/src/respondd.c
+++ b/package/gluon-node-info/src/respondd.c
@@ -69,6 +69,12 @@ static struct json_object * get_number(struct uci_context *ctx, struct uci_secti
 	return jso;
 }
 
+static void maybe_add_number(struct uci_context *ctx, struct uci_section *s, const char *name, struct json_object *parent) {
+	struct json_object *jso = get_number(ctx, s, name);
+	if (jso)
+		json_object_object_add(parent, name, jso);
+}
+
 static struct json_object * get_location(struct uci_context *ctx, struct uci_package *p) {
 	struct uci_section *s = get_first_section(p, "location");
 	if (!s)
@@ -80,17 +86,9 @@ static struct json_object * get_location(struct uci_context *ctx, struct uci_pac
 
 	struct json_object *ret = json_object_new_object();
 
-	struct json_object *latitude = get_number(ctx, s, "latitude");
-	if (latitude)
-		json_object_object_add(ret, "latitude", latitude);
-
-	struct json_object *longitude = get_number(ctx, s, "longitude");
-	if (longitude)
-		json_object_object_add(ret, "longitude", longitude);
-
-	struct json_object *altitude = get_number(ctx, s, "altitude");
-	if (altitude)
-		json_object_object_add(ret, "altitude", altitude);
+	maybe_add_number(ctx, s, "latitude", ret);
+	maybe_add_number(ctx, s, "longitude", ret);
+	maybe_add_number(ctx, s, "altitude", ret);
 
 	return ret;
 }