commit c6c398c6c51e48893f658eb6e6c08b47f41b085d
Author: jim-p <jimp@netgate.com>
Date:   Wed Nov 21 16:30:48 2018 -0200

    Fix #9121: Initialize arrays to prevent PHP 7 errors

diff --git a/src/etc/inc/auth.inc b/src/etc/inc/auth.inc
index f2df4b754d..60d5de9c90 100644
--- a/src/etc/inc/auth.inc
+++ b/src/etc/inc/auth.inc
@@ -829,7 +829,7 @@ function local_user_set_groups($user, $new_groups = NULL) {
 		if ($groupname == '' || in_array($groupname, $cur_groups)) {
 			continue;
 		}
-		$group = & $config['system']['group'][$groupindex[$groupname]];
+		$group = &$config['system']['group'][$groupindex[$groupname]];
 		$group['member'][] = $user['uid'];
 		$mod_groups[] = $group;
 
@@ -851,7 +851,7 @@ function local_user_set_groups($user, $new_groups = NULL) {
 		if (!isset($config['system']['group'][$groupindex[$groupname]])) {
 			continue;
 		}
-		$group = & $config['system']['group'][$groupindex[$groupname]];
+		$group = &$config['system']['group'][$groupindex[$groupname]];
 		if (is_array($group['member'])) {
 			$index = array_search($user['uid'], $group['member']);
 			array_splice($group['member'], $index, 1);
diff --git a/src/etc/inc/easyrule.inc b/src/etc/inc/easyrule.inc
index e654f1ac9a..18c8318556 100644
--- a/src/etc/inc/easyrule.inc
+++ b/src/etc/inc/easyrule.inc
@@ -98,13 +98,8 @@ function easyrule_block_rule_create($int = 'wan', $ipproto = "inet") {
 		return true;
 	}
 
-	/* No rules, start a new array */
-	if (!is_array($config['filter']['rule'])) {
-		$config['filter']['rule'] = array();
-	}
-
-	filter_rules_sort();
 	init_config_arr(array('filter', 'rule'));
+	filter_rules_sort();
 	$a_filter = &$config['filter']['rule'];
 
 	/* Make up a new rule */
@@ -160,11 +155,6 @@ function easyrule_block_alias_add($host, $int = 'wan') {
 		return false;
 	}
 
-	/* If there are no aliases, start an array */
-	if (!is_array($config['aliases']['alias'])) {
-		$config['aliases']['alias'] = array();
-	}
-
 	init_config_arr(array('aliases', 'alias'));
 	$a_aliases = &$config['aliases']['alias'];
 
@@ -286,13 +276,8 @@ function easyrule_block_host_add($host, $int = 'wan', $ipproto = "inet") {
 function easyrule_pass_rule_add($int, $proto, $srchost, $dsthost, $dstport, $ipproto) {
 	global $config;
 
-	/* No rules, start a new array */
-	if (!is_array($config['filter']['rule'])) {
-		$config['filter']['rule'] = array();
-	}
-
-	filter_rules_sort();
 	init_config_arr(array('filter', 'rule'));
+	filter_rules_sort();
 	$a_filter = &$config['filter']['rule'];
 
 	/* Make up a new rule */
diff --git a/src/etc/inc/filter.inc b/src/etc/inc/filter.inc
index 06d7422a90..f4f0f55bd9 100644
--- a/src/etc/inc/filter.inc
+++ b/src/etc/inc/filter.inc
@@ -212,7 +212,7 @@ function filter_delete_states_for_down_gateways() {
 			if (empty($a_gateways[$gateway['monitor']])) {
 				continue;
 			}
-			$gwstatus =& $a_gateways[$gateway['monitor']];
+			$gwstatus = &$a_gateways[$gateway['monitor']];
 			if (strstr($gwstatus['status'], "down")) {
 				$any_gateway_down = true;
 				break;
@@ -1612,7 +1612,7 @@ function filter_nat_rules_automatic_tonathosts($with_descr = false) {
 	foreach (get_staticroutes(false, false, true) as $route) {
 		$netip = explode("/", $route['network']);
 		if (isset($GatewaysList[$route['gateway']])) {
-			$gateway =& $GatewaysList[$route['gateway']];
+			$gateway = &$GatewaysList[$route['gateway']];
 			if (!interface_has_gateway($gateway['interface']) && is_private_ip($netip[0])) {
 				$tonathosts[] = $route['network'];
 				$descriptions[] = gettext("static route");
diff --git a/src/etc/inc/gwlb.inc b/src/etc/inc/gwlb.inc
index 7c0a436b00..f0ec9daae7 100644
--- a/src/etc/inc/gwlb.inc
+++ b/src/etc/inc/gwlb.inc
@@ -1972,12 +1972,7 @@ function validate_gateway($gateway_settings, $id = "", $parent_ip = "", $parent_
 function save_gateway($gateway_settings, $realid = "") {
 	global $config;
 
-	if (!is_array($config['gateways'])) {
-		$config['gateways'] = array();
-	}
-	if (!is_array($config['gateways']['gateway_item'])) {
-		$config['gateways']['gateway_item'] = array();
-	}
+	init_config_arr(array('gateways', 'gateway_item'));
 	$a_gateway_item = &$config['gateways']['gateway_item'];
 	$reloadif = "";
 	$gateway = array();
diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc
index 4ccd245ec7..0766682dff 100644
--- a/src/etc/inc/interfaces.inc
+++ b/src/etc/inc/interfaces.inc
@@ -1808,7 +1808,7 @@ function interfaces_carp_set_maintenancemode($carp_maintenancemode) {
 		$config["virtualip_carp_maintenancemode"] = true;
 		write_config(gettext("Enter CARP maintenance mode"));
 	}
-
+	init_config_arr(array('virtualip', 'vip'));
 	$viparr = &$config['virtualip']['vip'];
 
 	if (is_array($viparr)) {
@@ -5278,6 +5278,7 @@ function convert_real_interface_to_friendly_interface_name($interface = "wan", $
 	global $config;
 
 	/* XXX: For speed reasons reference directly the interface array */
+	init_config_arr(array('interfaces'));
 	$ifdescrs = &$config['interfaces'];
 	//$ifdescrs = get_configured_interface_list(true);
 
diff --git a/src/etc/inc/interfaces_fast.inc b/src/etc/inc/interfaces_fast.inc
index 67c1ae837e..d94132b344 100644
--- a/src/etc/inc/interfaces_fast.inc
+++ b/src/etc/inc/interfaces_fast.inc
@@ -61,6 +61,7 @@ function convert_real_interface_to_friendly_interface_name_fast() {
 
 	$out = array();
 	/* XXX: For speed reasons reference directly the interface array */
+	init_config_arr(array('interfaces'));
 	$ifdescrs = &$config['interfaces'];
 	$iffriendlynames = array_keys($ifdescrs);
 	$out = array_flip(get_real_interface_fast($iffriendlynames));
diff --git a/src/etc/inc/itemid.inc b/src/etc/inc/itemid.inc
index a0d51cd1da..ddce19b616 100644
--- a/src/etc/inc/itemid.inc
+++ b/src/etc/inc/itemid.inc
@@ -48,6 +48,7 @@ function delete_id($id, &$array) {
 	unset($array[$delete_index]);
 
 	// Update the separators
+	init_config_arr(array('filter', 'separator', strtolower($if)));
 	$a_separators = &$config['filter']['separator'][strtolower($if)];
 	// get rule index within interface
 	$ridx = ifridx($if, $delete_index);
diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc
index eef65663dc..2d7d23b8b6 100644
--- a/src/etc/inc/pfsense-utils.inc
+++ b/src/etc/inc/pfsense-utils.inc
@@ -807,6 +807,7 @@ function remove_text_from_file($file, $text) {
 function after_sync_bump_adv_skew() {
 	global $config, $g;
 	$processed_skew = 1;
+	init_config_arr(array('virtualip', 'vip'));
 	$a_vip = &$config['virtualip']['vip'];
 	foreach ($a_vip as $vipent) {
 		if ($vipent['advskew'] <> "") {
@@ -2704,7 +2705,7 @@ function xml2array($contents, $get_attributes = 1, $priority = 'tag') {
 					$current[$tag . '_attr'] = $attributes_data;
 				}
 				$repeated_tag_index[$tag . '_' . $level] = 1;
-				$current = & $current[$tag];
+				$current = &$current[$tag];
 			} else {
 				if (isset ($current[$tag][0])) {
 					$current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
@@ -2721,7 +2722,7 @@ function xml2array($contents, $get_attributes = 1, $priority = 'tag') {
 					}
 				}
 				$last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
-				$current = & $current[$tag][$last_item_index];
+				$current = &$current[$tag][$last_item_index];
 			}
 		} elseif ($type == "complete") {
 			if (!isset ($current[$tag])) {
@@ -2756,7 +2757,7 @@ function xml2array($contents, $get_attributes = 1, $priority = 'tag') {
 				}
 			}
 		} elseif ($type == 'close') {
-			$current = & $parent[$level -1];
+			$current = &$parent[$level -1];
 		}
 	}
 	return ($xml_array);
diff --git a/src/etc/inc/pkg-utils.inc b/src/etc/inc/pkg-utils.inc
index 9202720378..d147f23cd9 100644
--- a/src/etc/inc/pkg-utils.inc
+++ b/src/etc/inc/pkg-utils.inc
@@ -668,7 +668,7 @@ function sync_package($package_name) {
 		return;	 // No package belongs to the pkg_id passed to this function.
 	}
 
-	$package =& $config['installedpackages']['package'][$pkg_id];
+	$package = &$config['installedpackages']['package'][$pkg_id];
 	if (!file_exists("/usr/local/pkg/" . $package['configurationfile'])) {
 		log_error(sprintf(gettext("The %s package is missing its configuration file and must be reinstalled."), $package['name']));
 		delete_package_xml($package['name']);
@@ -950,14 +950,13 @@ function delete_package_xml($package_name, $when = "post-deinstall") {
 	pkg_debug(sprintf(gettext("Removing %s package... "), $package_name));
 	update_status(sprintf(gettext("Removing %s components..."), $package_name) . "\n");
 	/* parse package configuration */
-	init_config_arr(array('installedpackages', 'package'));
+	init_config_arr(array('installedpackages', 'package', $pkgid));
 	$packages = &$config['installedpackages']['package'];
+	$pkg_info = &$packages[$pkgid];
 	init_config_arr(array('installedpackages', 'menu'));
 	$menus = &$config['installedpackages']['menu'];
 	init_config_arr(array('installedpackages', 'service'));
 	$services = &$config['installedpackages']['service'];
-	init_config_arr(array('installedpackages', 'package', $pkgid));
-	$pkg_info = &$packages[$pkgid];
 	if (file_exists("/usr/local/pkg/" . $pkg_info['configurationfile'])) {
 		$pkg_config = parse_xml_config_pkg("/usr/local/pkg/" . $packages[$pkgid]['configurationfile'], "packagegui");
 		/* remove menu items */
diff --git a/src/etc/inc/priv.inc b/src/etc/inc/priv.inc
index 730b672f01..017dd15d15 100644
--- a/src/etc/inc/priv.inc
+++ b/src/etc/inc/priv.inc
@@ -214,18 +214,12 @@ function getPrivPages(& $entry, & $allowed_pages) {
 	}
 
 	foreach ($entry['priv'] as $pname) {
-		if (strncmp($pname, "page-", 5)) {
-			continue;
-		}
-		$priv = &$priv_list[$pname];
-		if (!is_array($priv)) {
-			continue;
-		}
-		$matches = &$priv['match'];
-		if (!is_array($matches)) {
+		if (strncmp($pname, "page-", 5) ||
+		    !is_array($priv_list[$pname]) ||
+		    !is_array($priv_list[$pname]['match'])) {
 			continue;
 		}
-		foreach ($matches as $match) {
+		foreach ($priv_list[$pname]['match'] as $match) {
 			$allowed_pages[] = $match;
 		}
 	}
diff --git a/src/etc/inc/service-utils.inc b/src/etc/inc/service-utils.inc
index 76fdda2bc2..cb187821a2 100644
--- a/src/etc/inc/service-utils.inc
+++ b/src/etc/inc/service-utils.inc
@@ -52,7 +52,7 @@ function write_rcfile($params) {
 	$towrite .= "\t{$params['start']}\n";
 	$towrite .= "}\n\n";
 	if (!empty($params['stop'])) {
-		$tokill =& $params['stop'];
+		$tokill = &$params['stop'];
 	} else if (!empty($params['executable'])) {
 		/* just nuke the executable */
 		$tokill = "/usr/bin/killall " . escapeshellarg($params['executable']);
@@ -92,7 +92,7 @@ function start_service($name, $after_sync = false) {
 				if ($service['rcfile']) {
 					$prefix = RCFILEPREFIX;
 					if (!empty($service['prefix'])) {
-						$prefix =& $service['prefix'];
+						$prefix = &$service['prefix'];
 					}
 					if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
 						mwexec_bg("{$prefix}{$service['rcfile']} start");
@@ -120,7 +120,7 @@ function stop_service($name) {
 				if ($service['rcfile']) {
 					$prefix = RCFILEPREFIX;
 					if (!empty($service['prefix'])) {
-						$prefix =& $service['prefix'];
+						$prefix = &$service['prefix'];
 					}
 					if (file_exists("{$prefix}{$service['rcfile']}") || is_link("{$prefix}{$service['rcfile']}")) {
 						mwexec("{$prefix}{$service['rcfile']} stop");
diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc
index d45e77638d..d9f4601c90 100644
--- a/src/etc/inc/services.inc
+++ b/src/etc/inc/services.inc
@@ -1726,7 +1726,8 @@ function services_dhcrelay_configure() {
 	/* kill any running dhcrelay */
 	killbypid("{$g['varrun_path']}/dhcrelay.pid");
 
-	$dhcrelaycfg =& $config['dhcrelay'];
+	init_config_arr(array('dhcrelay'));
+	$dhcrelaycfg = &$config['dhcrelay'];
 
 	/* DHCPRelay enabled on any interfaces? */
 	if (!isset($dhcrelaycfg['enable'])) {
@@ -1801,7 +1802,8 @@ function services_dhcrelay6_configure() {
 	/* kill any running dhcrelay */
 	killbypid("{$g['varrun_path']}/dhcrelay6.pid");
 
-	$dhcrelaycfg =& $config['dhcrelay6'];
+	init_config_arr(array('dhcrelay6'));
+	$dhcrelaycfg = &$config['dhcrelay6'];
 
 	/* DHCPv6 Relay enabled on any interfaces? */
 	if (!isset($dhcrelaycfg['enable'])) {
@@ -2731,7 +2733,7 @@ function configure_cron() {
 	$crontab_contents = file("/etc/crontab", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
 
 	for ($i = 0; $i < count($crontab_contents); $i++) {
-		$cron_item =& $crontab_contents[$i];
+		$cron_item = &$crontab_contents[$i];
 		if (strpos($cron_item, "# pfSense specific crontab entries") !== false) {
 			array_splice($crontab_contents, $i - 1);
 			break;
diff --git a/src/etc/inc/shaper.inc b/src/etc/inc/shaper.inc
index 6d0e760137..a23f4376e9 100644
--- a/src/etc/inc/shaper.inc
+++ b/src/etc/inc/shaper.inc
@@ -308,7 +308,8 @@ function get_queue_stats() {
 function &get_reference_to_me_in_config(&$mypath) {
 	global $config;
 
-	$ptr =& $config['shaper'];
+	init_config_arr(array('shaper'));
+	$ptr = &$config['shaper'];
 	foreach ($mypath as $indeks) {
 		if (!is_array($ptr)) {
 			$ptr = array();
@@ -319,7 +320,7 @@ function &get_reference_to_me_in_config(&$mypath) {
 		if (!is_array($ptr['queue'][$indeks])) {
 			$ptr['queue'][$indeks] = array();
 		}
-		$ptr =& $ptr['queue'][$indeks];
+		$ptr = &$ptr['queue'][$indeks];
 	}
 
 	return $ptr;
@@ -328,9 +329,10 @@ function &get_reference_to_me_in_config(&$mypath) {
 function unset_object_by_reference(&$mypath) {
 	global $config;
 
-	$ptr =& $config['shaper'];
+	init_config_arr(array('shaper'));
+	$ptr = &$config['shaper'];
 	for ($i = 0; $i < count($mypath) - 1; $i++) {
-		$ptr =& $ptr['queue'][$mypath[$i]];
+		$ptr = &$ptr['queue'][$mypath[$i]];
 	}
 	unset($ptr['queue'][$mypath[$i]]);
 }
@@ -338,9 +340,10 @@ function unset_object_by_reference(&$mypath) {
 function &get_dn_reference_to_me_in_config(&$mypath) {
 	global $config;
 
-	$ptr =& $config['dnshaper'];
+	init_config_arr(array('dnshaper'));
+	$ptr = &$config['dnshaper'];
 	foreach ($mypath as $indeks) {
-		$ptr =& $ptr['queue'][$indeks];
+		$ptr = &$ptr['queue'][$indeks];
 	}
 
 	return $ptr;
@@ -349,9 +352,10 @@ function &get_dn_reference_to_me_in_config(&$mypath) {
 function unset_dn_object_by_reference(&$mypath) {
 	global $config;
 
-	$ptr =& $config['dnshaper'];
+	init_config_arr(array('dnshaper'));
+	$ptr = &$config['dnshaper'];
 	for ($i = 0; $i < count($mypath) - 1; $i++) {
-		$ptr =& $ptr['queue'][$mypath[$i]];
+		$ptr = &$ptr['queue'][$mypath[$i]];
 	}
 	unset($ptr['queue'][$mypath[$i]]);
 }
@@ -522,8 +526,8 @@ function get_interface_bandwidth($object) {
 	global $altq_list_queues;
 
 	$int = $object->GetInterface();
-	$altq =& $altq_list_queues[$int];
-	if ($altq) {
+	if (isset($altq_list_queues[$int])) {
+		$altq = &$altq_list_queues[$int];
 		$bw_3 = $altq->GetBandwidth();
 		$bw_3 = $bw_3 * get_bandwidthtype_scale($altq->GetBwscale());
 		return floatval($bw_3);
@@ -5014,12 +5018,7 @@ function read_altq_config() {
 	global $altq_list_queues, $config;
 	$path = array();
 
-	if (!is_array($config['shaper'])) {
-		$config['shaper'] = array();
-	}
-	if (!is_array($config['shaper']['queue'])) {
-		$config['shaper']['queue'] = array();
-	}
+	init_config_arr(array('shaper', 'queue'));
 	$a_int = &$config['shaper']['queue'];
 
 	$altq_list_queues = array();
@@ -5055,18 +5054,12 @@ function read_dummynet_config() {
 	global $dummynet_pipe_list, $config;
 	$path = array();
 
-	if (!is_array($config['dnshaper'])) {
-		$config['dnshaper'] = array();
-	}
-	if (!is_array($config['dnshaper']['queue'])) {
-		$config['dnshaper']['queue'] = array();
-	}
+	init_config_arr(array('dnshaper', 'queue'));
 	$a_int = &$config['dnshaper']['queue'];
 
 	$dummynet_pipe_list = array();
 
-	if (!is_array($config['dnshaper']['queue']) ||
-	    !count($config['dnshaper']['queue'])) {
+	if (!count($config['dnshaper']['queue'])) {
 		return;
 	}
 
diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc
index 65462ef808..5751e83858 100644
--- a/src/etc/inc/system.inc
+++ b/src/etc/inc/system.inc
@@ -1190,14 +1190,10 @@ EOD;
 function system_webgui_create_certificate() {
 	global $config, $g;
 
-	if (!is_array($config['ca'])) {
-		$config['ca'] = array();
-	}
-	$a_ca =& $config['ca'];
-	if (!is_array($config['cert'])) {
-		$config['cert'] = array();
-	}
-	$a_cert =& $config['cert'];
+	init_config_arr(array('ca'));
+	$a_ca = &$config['ca'];
+	init_config_arr(array('cert'));
+	$a_cert = &$config['cert'];
 	log_error(gettext("Creating SSL Certificate for this host"));
 
 	$cert = array();
diff --git a/src/etc/inc/upgrade_config.inc b/src/etc/inc/upgrade_config.inc
index 0f22794922..3c0140d365 100644
--- a/src/etc/inc/upgrade_config.inc
+++ b/src/etc/inc/upgrade_config.inc
@@ -89,6 +89,7 @@ function upgrade_010_to_011() {
 	}
 
 	/* convert filter rules */
+	init_config_arr(array('filter', 'rule'));
 	$n = count($config['filter']['rule']);
 	for ($i = 0; $i < $n; $i++) {
 
@@ -133,6 +134,7 @@ function upgrade_010_to_011() {
 	}
 
 	/* convert shaper rules */
+	init_config_arr(array('pfqueueing', 'rule'));
 	$n = count($config['pfqueueing']['rule']);
 	if (is_array($config['pfqueueing']['rule'])) {
 		for ($i = 0; $i < $n; $i++) {
@@ -215,6 +217,7 @@ function upgrade_013_to_014() {
 	global $config;
 	/* convert shaper rules (make pipes) */
 	if (is_array($config['pfqueueing']['rule'])) {
+		init_config_arr(array('pfqueueing', 'pipe'));
 		$config['pfqueueing']['pipe'] = array();
 
 		for ($i = 0; isset($config['pfqueueing']['rule'][$i]); $i++) {
@@ -514,8 +517,9 @@ function upgrade_027_to_028() {
 
 function upgrade_028_to_029() {
 	global $config;
-	$rule_item = array();
+	init_config_arr(array('filter', 'rule'));
 	$a_filter = &$config['filter']['rule'];
+	$rule_item = array();
 	$rule_item['interface'] = "enc0";
 	$rule_item['type'] = "pass";
 	$rule_item['source']['any'] = true;
@@ -901,6 +905,7 @@ function upgrade_045_to_046() {
 	/* Upgrade load balancer from slb to relayd */
 	if (is_array($config['load_balancer']['virtual_server']) && count($config['load_balancer']['virtual_server'])) {
 		$vs_a = &$config['load_balancer']['virtual_server'];
+		init_config_arr(array('load_balancer', 'lbpool'));
 		$pool_a = &$config['load_balancer']['lbpool'];
 		$pools = array();
 		/* Index pools by name */
@@ -1970,11 +1975,8 @@ function upgrade_053_to_054() {
 		$gateway_group_arr = array();
 		$gateways = return_gateways_array();
 		$group_name_changes = array();
-		if (!is_array($config['gateways']['gateway_item'])) {
-			$config['gateways']['gateway_item'] = array();
-		}
-
-		$a_gateways =& $config['gateways']['gateway_item'];
+		init_config_arr(array('gateways', 'gateway_item'));
+		$a_gateways = &$config['gateways']['gateway_item'];
 		foreach ($lbpool_arr as $lbpool) {
 			if ($lbpool['type'] == "gateway") {
 				// Gateway Groups have to have valid names in pf, old lb pools did not. Clean them up.
@@ -2406,9 +2408,11 @@ function upgrade_062_to_063() {
 function upgrade_063_to_064() {
 	global $config;
 	$j = 0;
+	init_config_arr(array('ppps', 'ppp'));
+	init_config_arr(array('interfaces'));
 	$ifcfg = &$config['interfaces'];
 
-	if (is_array($config['ppps']['ppp']) && count($config['ppps']['ppp'])) {
+	if (count($config['ppps']['ppp'])) {
 		foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
 			$config['ppps']['ppp'][$pppid]['if'] = "ppp".$j;
 			$config['ppps']['ppp'][$pppid]['ptpid'] = $j;
@@ -2426,9 +2430,6 @@ function upgrade_063_to_064() {
 		}
 	}
 
-	if (!is_array($config['ppps']['ppp'])) {
-		$config['ppps']['ppp'] = array();
-	}
 	$a_ppps = &$config['ppps']['ppp'];
 
 	foreach ($ifcfg as $ifname => $ifinfo) {
@@ -2514,7 +2515,8 @@ function upgrade_064_to_065() {
 function upgrade_065_to_066() {
 	global $config;
 
-	$dhcrelaycfg =& $config['dhcrelay'];
+	init_config_arr(array('dhcrelay'));
+	$dhcrelaycfg = &$config['dhcrelay'];
 
 	if (is_array($dhcrelaycfg)) {
 		$dhcrelayifs = array();
@@ -3179,7 +3181,7 @@ function upgrade_090_to_091() {
 function upgrade_091_to_092() {
 	global $config;
 
-	if (is_array($config['nat']['advancedoutbound']) && is_array($config['nat']['advancedoutbound']['rule'])) {
+	if (is_array($config['nat']['advancedoutbound']['rule'])) {
 		$nat_rules = &$config['nat']['advancedoutbound']['rule'];
 		for ($i = 0; isset($nat_rules[$i]); $i++) {
 			if (empty($nat_rules[$i]['interface'])) {
@@ -3742,11 +3744,8 @@ function upgrade_117_to_118() {
 		unset($config['system']['cert']);
 	}
 
-	if (!isset($config['ipsec']['phase1'])) {
-		return;
-	}
-
-	$a_phase1 =& $config['ipsec']['phase1'];
+	init_config_arr(array('ipsec', 'phase1'));
+	$a_phase1 = &$config['ipsec']['phase1'];
 
 	foreach ($a_phase1 as &$ph1_entry) {
 		// update asn1dn strings from racoon's format to strongswan's
@@ -3769,7 +3768,8 @@ function upgrade_118_to_119() {
 	}
 
 	// change peerid_type to 'any' for EAP types to retain previous behavior of omitting rightid
-	$a_phase1 =& $config['ipsec']['phase1'];
+	init_config_arr(array('ipsec', 'phase1'));
+	$a_phase1 = &$config['ipsec']['phase1'];
 
 	foreach ($a_phase1 as &$ph1_entry) {
 		if (strstr($ph1_entry['authentication_method'], 'eap')) {
@@ -3803,7 +3803,7 @@ function upgrade_120_to_121() {
 		return;
 	}
 
-	$miniupnpd =& $config['installedpackages']['miniupnpd']['config'][0];
+	$miniupnpd = &$config['installedpackages']['miniupnpd']['config'][0];
 
 	$miniupnpd['row'] = array();
 
@@ -3834,7 +3834,7 @@ function upgrade_122_to_123() {
 
 	// Cleanup firewall rules
 	if (isset($config['filter']['rule']) && is_array($config['filter']['rule'])) {
-		$rules =& $config['filter']['rule'];
+		$rules = &$config['filter']['rule'];
 		$last_rule = count($rules) - 1;
 		// Process in reverse order to be able to unset items
 		for ($i = $last_rule; $i >= 0; $i--) {
@@ -3855,7 +3855,7 @@ function upgrade_122_to_123() {
 
 	// Cleanup 1:1 NAT rules
 	if (isset($config['nat']['onetoone']) && is_array($config['nat']['onetoone'])) {
-		$onetoone =& $config['nat']['onetoone'];
+		$onetoone = &$config['nat']['onetoone'];
 		$last_rule = count($onetoone) - 1;
 		// Process in reverse order to be able to unset items
 		for ($i = $last_rule; $i >= 0; $i--) {
@@ -3876,7 +3876,7 @@ function upgrade_122_to_123() {
 
 	// Cleanup npt NAT rules
 	if (isset($config['nat']['npt']) && is_array($config['nat']['npt'])) {
-		$npt =& $config['nat']['npt'];
+		$npt = &$config['nat']['npt'];
 		$last_rule = count($npt) - 1;
 		// Process in reverse order to be able to unset items
 		for ($i = $last_rule; $i >= 0; $i--) {
@@ -3889,7 +3889,7 @@ function upgrade_122_to_123() {
 
 	// Cleanup Port-forward NAT rules
 	if (isset($config['nat']['rule']) && is_array($config['nat']['rule'])) {
-		$nat_rules =& $config['nat']['rule'];
+		$nat_rules = &$config['nat']['rule'];
 		$last_rule = count($nat_rules) - 1;
 		// Process in reverse order to be able to unset items
 		for ($i = $last_rule; $i >= 0; $i--) {
@@ -3910,7 +3910,7 @@ function upgrade_122_to_123() {
 
 	// Cleanup Port-forward NAT rules
 	if (isset($config['nat']['outbound']['rule']) && is_array($config['nat']['outbound']['rule'])) {
-		$out_rules =& $config['nat']['outbound']['rule'];
+		$out_rules = &$config['nat']['outbound']['rule'];
 		$last_rule = count($out_rules) - 1;
 		// Process in reverse order to be able to unset items
 		for ($i = $last_rule; $i >= 0; $i--) {
@@ -4378,12 +4378,7 @@ function upgrade_141_to_142() {
 	global $config;
 	/* Convert Namecheap type DynDNS entries to the new split hostname and domain format */
 
-	if (!is_array($config['dyndnses'])) {
-		$config['dyndnses'] = array();
-	}
-	if (!is_array($config['dyndnses']['dyndns'])) {
-		$config['dyndnses']['dyndns'] = array();
-	}
+	init_config_arr(array('dyndnses', 'dyndns'));
 	$a_dyndns = &$config['dyndnses']['dyndns'];
 
 	foreach ($a_dyndns as &$dyndns) {
@@ -4950,12 +4945,7 @@ function upgrade_156_to_157() {
 	global $config;
 	/* Convert Cloudflare and GratisDNS type DynDNS entries to the new split hostname and domain format */
 
-	if (!is_array($config['dyndnses'])) {
-		$config['dyndnses'] = array();
-	}
-	if (!is_array($config['dyndnses']['dyndns'])) {
-		$config['dyndnses']['dyndns'] = array();
-	}
+	init_config_arr(array('dyndnses', 'dyndns'));
 	$a_dyndns = &$config['dyndnses']['dyndns'];
 
 	foreach ($a_dyndns as &$dyndns) {
@@ -4983,12 +4973,7 @@ function upgrade_157_to_158() {
 	global $config;
 	/* Convert Dynamic DNS passwords to base64 encoding. Redmine #6688 */
 
-	if (!is_array($config['dyndnses'])) {
-		$config['dyndnses'] = array();
-	}
-	if (!is_array($config['dyndnses']['dyndns'])) {
-		$config['dyndnses']['dyndns'] = array();
-	}
+	init_config_arr(array('dyndnses', 'dyndns'));
 	$a_dyndns = &$config['dyndnses']['dyndns'];
 
 	foreach ($a_dyndns as &$dyndns) {
@@ -5490,7 +5475,7 @@ function upgrade_173_to_174() {
 function upgrade_174_to_175() {
 	global $config;
 	init_config_arr(array('ipsec', 'phase1'));
-	if (is_array($config['ipsec']['phase1'])) {
+	if (count($config['ipsec']['phase1'])) {
 		$a_phase1 = &$config['ipsec']['phase1'];
 		foreach($a_phase1 as &$phase1) {
 			if (empty($phase1)) {
@@ -5759,10 +5744,7 @@ function upgrade_184_to_185() {
 	if (is_array($config['installedpackages']['autoconfigbackup']['config'][0])) {
 		$acbpkg = &$config['installedpackages']['autoconfigbackup']['config'][0];
 
-		if (!is_array($config['system']['acb'])) {
-			$config['system']['acb'] = array();
-		}
-
+		init_config_arr(array('system', 'acb'));
 		$acb = &$config['system']['acb'];
 		$acb['enable'] = ($acbpkg['enable_acb'] != 'disabled') ?  'yes':'no';
 		$acb['gold_encryption_password'] = $acbpkg['crypto_password'];
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc
index cd33d5918c..4367118283 100644
--- a/src/etc/inc/util.inc
+++ b/src/etc/inc/util.inc
@@ -1268,7 +1268,9 @@ function get_configured_vip_list($family = 'all', $type = VIP_ALL) {
 	global $config;
 
 	$list = array();
-	if (!is_array($config['virtualip']['vip']) || empty($config['virtualip']['vip'])) {
+	if (!is_array($config['virtualip']) ||
+	    !is_array($config['virtualip']['vip']) ||
+	    empty($config['virtualip']['vip'])) {
 		return ($list);
 	}
 
@@ -1328,7 +1330,9 @@ function get_configured_vip_subnetv6($vipinterface = '') {
 function get_configured_vip_detail($vipinterface = '', $family = 'inet', $what = 'ip') {
 	global $config;
 
-	if (empty($vipinterface) || !is_array($config['virtualip']['vip']) ||
+	if (empty($vipinterface) ||
+	    !is_array($config['virtualip']) ||
+	    !is_array($config['virtualip']['vip']) ||
 	    empty($config['virtualip']['vip'])) {
 		return (NULL);
 	}
diff --git a/src/etc/phpshellsessions/disablecarp b/src/etc/phpshellsessions/disablecarp
index 03999932e5..f390af6c10 100644
--- a/src/etc/phpshellsessions/disablecarp
+++ b/src/etc/phpshellsessions/disablecarp
@@ -25,6 +25,7 @@ require_once("util.inc");
 
 set_single_sysctl("net.inet.carp.allow", "0");
 if (is_array($config['virtualip']['vip'])) {
+	init_config_arr(array('virtualip', 'vip'));
 	$viparr = &$config['virtualip']['vip'];
 	foreach ($viparr as $vip) {
 		switch ($vip['mode']) {
diff --git a/src/etc/phpshellsessions/enablecarp b/src/etc/phpshellsessions/enablecarp
index 24011fcce7..0897296faa 100644
--- a/src/etc/phpshellsessions/enablecarp
+++ b/src/etc/phpshellsessions/enablecarp
@@ -24,6 +24,7 @@ require_once("interfaces.inc");
 require_once("util.inc");
 
 if (is_array($config['virtualip']['vip'])) {
+	init_config_arr(array('virtualip', 'vip'));
 	$viparr = &$config['virtualip']['vip'];
 	foreach ($viparr as $vip) {
 		switch ($vip['mode']) {
diff --git a/src/etc/rc.initial.setlanip b/src/etc/rc.initial.setlanip
index 6a1ae28d47..f43ec53758 100755
--- a/src/etc/rc.initial.setlanip
+++ b/src/etc/rc.initial.setlanip
@@ -201,9 +201,7 @@ function next_unused_gateway_name($interface) {
 
 function add_gateway_to_config($interface, $gatewayip, $inet_type) {
 	global $g, $config, $dry_run;
-	if (!is_array($config['gateways']['gateway_item'])) {
-		$config['gateways']['gateway_item'] = array();
-	}
+	init_config_arr(array('gateways', 'gateway_item'));
 	$a_gateways = &$config['gateways']['gateway_item'];
 	if ($dry_run) {
 		print_r($a_gateways);
diff --git a/src/usr/local/www/diag_dns.php b/src/usr/local/www/diag_dns.php
index ccfd81cc5b..cefcf9a154 100644
--- a/src/usr/local/www/diag_dns.php
+++ b/src/usr/local/www/diag_dns.php
@@ -31,16 +31,7 @@ require_once("guiconfig.inc");
 
 $host = trim($_REQUEST['host'], " \t\n\r\0\x0B[];\"'");
 
-/* If this section of config.xml has not been populated yet we need to set it up
-*/
-if (!is_array($config['aliases'])) {
-	$config['aliases'] = array();
-}
-
-if (!is_array($config['aliases']['alias'])) {
-	$config['aliases']['alias'] = array();
-}
-
+init_config_arr(array('aliases', 'alias'));
 $a_aliases = &$config['aliases']['alias'];
 
 $aliasname = substr(str_replace(array(".", "-"), "_", $host), 0, 31);
diff --git a/src/usr/local/www/firewall_aliases.php b/src/usr/local/www/firewall_aliases.php
index 335059d6e9..be2bcfd8f4 100644
--- a/src/usr/local/www/firewall_aliases.php
+++ b/src/usr/local/www/firewall_aliases.php
@@ -35,14 +35,7 @@ require_once("functions.inc");
 require_once("filter.inc");
 require_once("shaper.inc");
 
-if (!is_array($config['aliases'])) {
-	$config['aliases'] = array();
-}
-
-if (!is_array($config['aliases']['alias'])) {
-	$config['aliases']['alias'] = array();
-}
-
+init_config_arr(array('aliases', 'alias'));
 $a_aliases = &$config['aliases']['alias'];
 
 $tab = ($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/", "", $_REQUEST['tab']));
diff --git a/src/usr/local/www/firewall_aliases_edit.php b/src/usr/local/www/firewall_aliases_edit.php
index 39dee98feb..2b190f1485 100644
--- a/src/usr/local/www/firewall_aliases_edit.php
+++ b/src/usr/local/www/firewall_aliases_edit.php
@@ -55,14 +55,7 @@ $reserved_ifs = get_configured_interface_list(true);
 $pf_reserved_keywords = array_merge($pf_reserved_keywords, $reserved_ifs, $reserved_table_names);
 $max_alias_addresses = 5000;
 
-if (!is_array($config['aliases'])) {
-	$config['aliases'] = array();
-}
-
-if (!is_array($config['aliases']['alias'])) {
-	$config['aliases']['alias'] = array();
-}
-
+init_config_arr(array('aliases', 'alias'));
 $a_aliases = &$config['aliases']['alias'];
 
 // Debugging
diff --git a/src/usr/local/www/firewall_aliases_import.php b/src/usr/local/www/firewall_aliases_import.php
index f90533a761..dae3cfc4b5 100644
--- a/src/usr/local/www/firewall_aliases_import.php
+++ b/src/usr/local/www/firewall_aliases_import.php
@@ -55,13 +55,7 @@ if (empty($tab)) {
 $pgtitle = array(gettext("Firewall"), gettext("Aliases"), gettext("Bulk import"));
 $pglinks = array("", "firewall_aliases.php?tab=" . $tab, "@self");
 
-if (!is_array($config['aliases'])) {
-	$config['aliases'] = array();
-}
-
-if (!is_array($config['aliases']['alias'])) {
-	$config['aliases']['alias'] = array();
-}
+init_config_arr(array('aliases', 'alias'));
 $a_aliases = &$config['aliases']['alias'];
 
 if ($_POST) {
diff --git a/src/usr/local/www/firewall_nat.php b/src/usr/local/www/firewall_nat.php
index 335aff0502..40f56b56c9 100644
--- a/src/usr/local/www/firewall_nat.php
+++ b/src/usr/local/www/firewall_nat.php
@@ -39,6 +39,7 @@ require_once("itemid.inc");
 init_config_arr(array('nat', 'separator'));
 init_config_arr(array('nat', 'rule'));
 $a_nat = &$config['nat']['rule'];
+$a_separators = &$config['nat']['separator'];
 
 /* update rule order, POST[rule] is an array of ordered IDs */
 if (array_key_exists('order-store', $_REQUEST) && have_natpfruleint_access($natent['interface'])) {
@@ -107,7 +108,6 @@ if (($_POST['act'] == "del") && have_natpfruleint_access($natent['interface']))
 		unset($a_nat[$_POST['id']]);
 
 		// Update the separators
-		$a_separators = &$config['nat']['separator'];
 		$ridx = $_POST['id'];
 		$mvnrows = -1;
 		move_separators($a_separators, $ridx, $mvnrows);
@@ -128,7 +128,6 @@ if (isset($_POST['del_x']) && have_natpfruleint_access($natent['interface'])) {
 
 	/* delete selected rules */
 	if (is_array($_POST['rule']) && count($_POST['rule'])) {
-		$a_separators = &$config['nat']['separator'];
 		$num_deleted = 0;
 
 		foreach ($_POST['rule'] as $rulei) {
diff --git a/src/usr/local/www/firewall_nat_edit.php b/src/usr/local/www/firewall_nat_edit.php
index 0caeb317ba..cd7139df07 100644
--- a/src/usr/local/www/firewall_nat_edit.php
+++ b/src/usr/local/www/firewall_nat_edit.php
@@ -46,9 +46,11 @@ foreach ($ifdisp as $kif => $kdescr) {
 	$specialsrcdst[] = "{$kif}ip";
 }
 
+init_config_arr(array('filter', 'rule'));
 init_config_arr(array('nat', 'separator'));
 init_config_arr(array('nat', 'rule'));
 $a_nat = &$config['nat']['rule'];
+$a_separators = &$config['nat']['separator'];
 
 if (isset($_REQUEST['id']) && is_numericint($_REQUEST['id'])) {
 	$id = $_REQUEST['id'];
@@ -512,7 +514,6 @@ if ($_POST['save']) {
 				array_splice($a_nat, $after+1, 0, array($natent));
 
 				// Update the separators
-				$a_separators = &$config['nat']['separator'];
 				$ridx = $after;
 				$mvnrows = +1;
 				move_separators($a_separators, $ridx, $mvnrows);
diff --git a/src/usr/local/www/firewall_rules.php b/src/usr/local/www/firewall_rules.php
index 2c6c302cc4..a6fea90b05 100644
--- a/src/usr/local/www/firewall_rules.php
+++ b/src/usr/local/www/firewall_rules.php
@@ -108,14 +108,7 @@ function delete_nat_association($id) {
 	}
 }
 
-if (!is_array($config['filter'])) {
-	$config['filter'] = array();
-}
-
-if (!is_array($config['filter']['rule'])) {
-	$config['filter']['rule'] = array();
-}
-
+init_config_arr(array('filter', 'rule'));
 filter_rules_sort();
 $a_filter = &$config['filter']['rule'];
 
@@ -150,6 +143,7 @@ if ($_POST['act'] == "del") {
 		unset($a_filter[$_POST['id']]);
 
 		// Update the separators
+		init_config_arr(array('filter', 'separator', strtolower($if)));
 		$a_separators = &$config['filter']['separator'][strtolower($if)];
 		$ridx = ifridx($if, $_POST['id']);	// get rule index within interface
 		$mvnrows = -1;
@@ -174,6 +168,7 @@ if (isset($_POST['del_x'])) {
 	$deleted = false;
 
 	if (is_array($_POST['rule']) && count($_POST['rule'])) {
+		init_config_arr(array('filter', 'separator', strtolower($if)));
 		$a_separators = &$config['filter']['separator'][strtolower($if)];
 		$num_deleted = 0;
 
@@ -505,14 +500,8 @@ foreach ($a_filter as $filteri => $filterent):
 			pprint_port($filterent['destination']['port'])
 		);
 
-		if (!is_array($config['schedules'])) {
-			$config['schedules'] = array();
-		}
-
-		if (!is_array($config['schedules']['schedule'])) {
-			$config['schedules']['schedule'] = array();
-		}
 		//build Schedule popup box
+		init_config_arr(array('schedules', 'schedule'));
 		$a_schedules = &$config['schedules']['schedule'];
 		$schedule_span_begin = "";
 		$schedule_span_end = "";
diff --git a/src/usr/local/www/firewall_rules_edit.php b/src/usr/local/www/firewall_rules_edit.php
index 3db8f720bb..ac86dc8162 100644
--- a/src/usr/local/www/firewall_rules_edit.php
+++ b/src/usr/local/www/firewall_rules_edit.php
@@ -139,10 +139,7 @@ foreach ($ifdisp as $kif => $kdescr) {
 	$specialsrcdst[] = "{$kif}ip";
 }
 
-if (!is_array($config['filter']['rule'])) {
-	$config['filter']['rule'] = array();
-}
-
+init_config_arr(array('filter', 'rule'));
 filter_rules_sort();
 $a_filter = &$config['filter']['rule'];
 
@@ -608,7 +605,7 @@ if ($_POST['save']) {
 	}
 
 	if ($_POST['proto'] == "icmp") {
-		$t =& $_POST['icmptype'];
+		$t = $_POST['icmptype'];
 		if (isset($t) && !is_array($t)) {
 			// shouldn't happen but avoids making assumptions for data-sanitising
 			$input_errors[] = gettext("ICMP types expected to be a list if present, but is not.");
@@ -965,6 +962,7 @@ if ($_POST['save']) {
 				$a_filter[$id] = $filterent;
 			} else {							// rule moved to different interface
 				// Update the separators of previous interface.
+				init_config_arr(array('filter', 'separator', strtolower($if)));
 				$a_separators = &$config['filter']['separator'][strtolower($if)];
 				$ridx = ifridx($if, $id);		// get rule index within interface
 				$mvnrows = -1;
@@ -973,6 +971,7 @@ if ($_POST['save']) {
 				$a_filter[$id] = $filterent;	// save edited rule to new interface
 
 				// Update the separators of new interface.
+				init_config_arr(array('filter', 'separator', strtolower($tmpif)));
 				$a_separators = &$config['filter']['separator'][strtolower($tmpif)];
 				$ridx = ifridx($tmpif, $id);	// get rule index within interface
 				if ($ridx == 0) {				// rule was placed at the top
@@ -1004,6 +1003,7 @@ if ($_POST['save']) {
 				}
 
 				// Update the separators
+				init_config_arr(array('filter', 'separator', strtolower($tmpif)));
 				$a_separators = &$config['filter']['separator'][strtolower($tmpif)];
 				$ridx = ifridx($tmpif, $after);	// get rule index within interface
 				$mvnrows = +1;
diff --git a/src/usr/local/www/firewall_virtual_ip.php b/src/usr/local/www/firewall_virtual_ip.php
index 11ad2b9926..50c8bfaa07 100644
--- a/src/usr/local/www/firewall_virtual_ip.php
+++ b/src/usr/local/www/firewall_virtual_ip.php
@@ -36,14 +36,7 @@ require_once("functions.inc");
 require_once("filter.inc");
 require_once("shaper.inc");
 
-if (!is_array($config['virtualip'])) {
-	$config['virtualip'] = array();
-}
-
-if (!is_array($config['virtualip']['vip'])) {
-	$config['virtualip']['vip'] = array();
-}
-
+init_config_arr(array('virtualip', 'vip'));
 $a_vip = &$config['virtualip']['vip'];
 
 if ($_POST['apply']) {
diff --git a/src/usr/local/www/firewall_virtual_ip_edit.php b/src/usr/local/www/firewall_virtual_ip_edit.php
index 9e65b43adb..53de79097c 100644
--- a/src/usr/local/www/firewall_virtual_ip_edit.php
+++ b/src/usr/local/www/firewall_virtual_ip_edit.php
@@ -35,14 +35,7 @@ require_once("guiconfig.inc");
 require_once("filter.inc");
 require_once("shaper.inc");
 
-if (!is_array($config['virtualip'])) {
-		$config['virtualip'] = array();
-}
-
-if (!is_array($config['virtualip']['vip'])) {
-		$config['virtualip']['vip'] = array();
-}
-
+init_config_arr(array('virtualip', 'vip'));
 $a_vip = &$config['virtualip']['vip'];
 
 if (isset($_REQUEST['id']) && is_numericint($_REQUEST['id'])) {
diff --git a/src/usr/local/www/interfaces.php b/src/usr/local/www/interfaces.php
index 056713be26..b60da90d39 100755
--- a/src/usr/local/www/interfaces.php
+++ b/src/usr/local/www/interfaces.php
@@ -41,6 +41,10 @@ require_once("rrd.inc");
 require_once("vpn.inc");
 require_once("xmlparse_attr.inc");
 
+function remove_bad_chars($string) {
+	return preg_replace('/[^a-z_0-9]/i', '', $string);
+}
+
 define("ANTENNAS", false);
 
 if (isset($_POST['referer'])) {
@@ -72,26 +76,10 @@ if (!is_array($pconfig)) {
 	$pconfig = array();
 }
 
-if (!is_array($config['ppps'])) {
-	$config['ppps'] = array();
-}
-if (!is_array($config['ppps']['ppp'])) {
-	$config['ppps']['ppp'] = array();
-}
+init_config_arr(array('ppps', 'ppp'));
 $a_ppps = &$config['ppps']['ppp'];
 
-function remove_bad_chars($string) {
-	return preg_replace('/[^a-z_0-9]/i', '', $string);
-}
-
-if (!is_array($config['gateways'])) {
-	$config['gateways'] = array();
-}
-
-if (!is_array($config['gateways']['gateway_item'])) {
-	$config['gateways']['gateway_item'] = array();
-}
-
+init_config_arr(array('gateways', 'gateway_item'));
 $a_gateways = &$config['gateways']['gateway_item'];
 
 $interfaces = get_configured_interface_with_descr();
@@ -106,6 +94,7 @@ foreach ($no_address_interfaces as $ifbl) {
 	}
 }
 
+init_config_arr(array('interfaces', $if));
 $wancfg = &$config['interfaces'][$if];
 $old_wancfg = $wancfg;
 $old_wancfg['realif'] = get_real_interface($if);
diff --git a/src/usr/local/www/interfaces_bridge.php b/src/usr/local/www/interfaces_bridge.php
index 5e45ea284e..f4147e8450 100644
--- a/src/usr/local/www/interfaces_bridge.php
+++ b/src/usr/local/www/interfaces_bridge.php
@@ -28,15 +28,8 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['bridges'])) {
-	$config['bridges'] = array();
-}
-
-if (!is_array($config['bridges']['bridged'])) {
-	$config['bridges']['bridged'] = array();
-}
-
-$a_bridges = &$config['bridges']['bridged'] ;
+init_config_arr(array('bridges', 'bridged'));
+$a_bridges = &$config['bridges']['bridged'];
 
 function bridge_inuse($num) {
 	global $config, $a_bridges;
diff --git a/src/usr/local/www/interfaces_bridge_edit.php b/src/usr/local/www/interfaces_bridge_edit.php
index 9476ade24f..c025c1484c 100644
--- a/src/usr/local/www/interfaces_bridge_edit.php
+++ b/src/usr/local/www/interfaces_bridge_edit.php
@@ -28,14 +28,6 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['bridges'])) {
-	$config['bridges'] = array();
-}
-
-if (!is_array($config['bridges']['bridged'])) {
-	$config['bridges']['bridged'] = array();
-}
-
 function is_aoadv_used($pconfig) {
 	if (($pconfig['static'] !="") ||
 	    ($pconfig['private'] != "") ||
@@ -60,6 +52,7 @@ function is_aoadv_used($pconfig) {
 	return false;
 }
 
+init_config_arr(array('bridges', 'bridged'));
 $a_bridges = &$config['bridges']['bridged'];
 
 $ifacelist = get_configured_interface_with_descr();
diff --git a/src/usr/local/www/interfaces_gif.php b/src/usr/local/www/interfaces_gif.php
index 91cc20bf9d..53739c88dd 100644
--- a/src/usr/local/www/interfaces_gif.php
+++ b/src/usr/local/www/interfaces_gif.php
@@ -28,13 +28,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['gifs'])) {
-	$config['gifs'] = array();
-}
-if (!is_array($config['gifs']['gif'])) {
-	$config['gifs']['gif'] = array();
-}
-
+init_config_arr(array('gifs', 'gif'));
 $a_gifs = &$config['gifs']['gif'] ;
 
 function gif_inuse($num) {
diff --git a/src/usr/local/www/interfaces_gif_edit.php b/src/usr/local/www/interfaces_gif_edit.php
index 18ff9af329..f8e87328db 100644
--- a/src/usr/local/www/interfaces_gif_edit.php
+++ b/src/usr/local/www/interfaces_gif_edit.php
@@ -28,13 +28,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['gifs'])) {
-	$config['gifs'] = array();
-}
-if (!is_array($config['gifs']['gif'])) {
-	$config['gifs']['gif'] = array();
-}
-
+init_config_arr(array('gifs', 'gif'));
 $a_gifs = &$config['gifs']['gif'];
 $id = $_REQUEST['id'];
 
diff --git a/src/usr/local/www/interfaces_gre.php b/src/usr/local/www/interfaces_gre.php
index a5833defaf..62ca5d8636 100644
--- a/src/usr/local/www/interfaces_gre.php
+++ b/src/usr/local/www/interfaces_gre.php
@@ -29,13 +29,7 @@
 require_once("guiconfig.inc");
 require_once("functions.inc");
 
-if (!is_array($config['gres'])) {
-	$config['gres'] = array();
-}
-if (!is_array($config['gres']['gre'])) {
-	$config['gres']['gre'] = array();
-}
-
+init_config_arr(array('gres', 'gre'));
 $a_gres = &$config['gres']['gre'] ;
 
 function gre_inuse($num) {
diff --git a/src/usr/local/www/interfaces_gre_edit.php b/src/usr/local/www/interfaces_gre_edit.php
index a46603e875..c624c32cac 100644
--- a/src/usr/local/www/interfaces_gre_edit.php
+++ b/src/usr/local/www/interfaces_gre_edit.php
@@ -29,13 +29,7 @@
 require_once("guiconfig.inc");
 require_once("functions.inc");
 
-if (!is_array($config['gres'])) {
-	$config['gres'] = array();
-}
-if (!is_array($config['gres']['gre'])) {
-	$config['gres']['gre'] = array();
-}
-
+init_config_arr(array('gres', 'gre'));
 $a_gres = &$config['gres']['gre'];
 $id = $_REQUEST['id'];
 
diff --git a/src/usr/local/www/interfaces_groups.php b/src/usr/local/www/interfaces_groups.php
index c9dee04206..cec72e2bde 100644
--- a/src/usr/local/www/interfaces_groups.php
+++ b/src/usr/local/www/interfaces_groups.php
@@ -29,14 +29,7 @@
 require_once("guiconfig.inc");
 require_once("functions.inc");
 
-if (!is_array($config['ifgroups'])) {
-	$config['ifgroups'] = array();
-}
-
-if (!is_array($config['ifgroups']['ifgroupentry'])) {
-	$config['ifgroups']['ifgroupentry'] = array();
-}
-
+init_config_arr(array('ifgroups', 'ifgroupentry'));
 $a_ifgroups = &$config['ifgroups']['ifgroupentry'];
 
 if ($_POST['act'] == "del") {
diff --git a/src/usr/local/www/interfaces_groups_edit.php b/src/usr/local/www/interfaces_groups_edit.php
index 141267ef03..d55dc2cefa 100644
--- a/src/usr/local/www/interfaces_groups_edit.php
+++ b/src/usr/local/www/interfaces_groups_edit.php
@@ -34,14 +34,7 @@ $pgtitle = array(gettext("Interfaces"), gettext("Interface Groups"), gettext("Ed
 $pglinks = array("", "interfaces_groups.php", "@self");
 $shortcut_section = "interfaces";
 
-if (!is_array($config['ifgroups'])) {
-	$config['ifgroups'] = array();
-}
-
-if (!is_array($config['ifgroups']['ifgroupentry'])) {
-	$config['ifgroups']['ifgroupentry'] = array();
-}
-
+init_config_arr(array('ifgroups', 'ifgroupentry'));
 $a_ifgroups = &$config['ifgroups']['ifgroupentry'];
 $id = $_REQUEST['id'];
 
diff --git a/src/usr/local/www/interfaces_lagg.php b/src/usr/local/www/interfaces_lagg.php
index 591f62e069..f7d2d6e0a2 100644
--- a/src/usr/local/www/interfaces_lagg.php
+++ b/src/usr/local/www/interfaces_lagg.php
@@ -28,14 +28,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['laggs'])) {
-	$config['laggs'] = array();
-}
-
-if (!is_array($config['laggs']['lagg'])) {
-	$config['laggs']['lagg'] = array();
-}
-
+init_config_arr(array('laggs', 'lagg'));
 $a_laggs = &$config['laggs']['lagg'] ;
 
 function lagg_inuse($num) {
diff --git a/src/usr/local/www/interfaces_lagg_edit.php b/src/usr/local/www/interfaces_lagg_edit.php
index f88480873a..2a98d27613 100644
--- a/src/usr/local/www/interfaces_lagg_edit.php
+++ b/src/usr/local/www/interfaces_lagg_edit.php
@@ -28,14 +28,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['laggs'])) {
-	$config['laggs'] = array();
-}
-
-if (!is_array($config['laggs']['lagg'])) {
-	$config['laggs']['lagg'] = array();
-}
-
+init_config_arr(array('laggs', 'lagg'));
 $a_laggs = &$config['laggs']['lagg'];
 
 $portlist = get_interface_list();
diff --git a/src/usr/local/www/interfaces_ppps_edit.php b/src/usr/local/www/interfaces_ppps_edit.php
index d3a27d1818..6eb5f115a5 100644
--- a/src/usr/local/www/interfaces_ppps_edit.php
+++ b/src/usr/local/www/interfaces_ppps_edit.php
@@ -39,14 +39,7 @@ define("CRON_WEEKLY_PATTERN", "0 0 * * 0");
 define("CRON_DAILY_PATTERN", "0 0 * * *");
 define("CRON_HOURLY_PATTERN", "0 * * * *");
 
-if (!is_array($config['ppps'])) {
-	$config['ppps'] = array();
-}
-
-if (!is_array($config['ppps']['ppp'])) {
-	$config['ppps']['ppp'] = array();
-}
-
+init_config_arr(array('ppps', 'ppp'));
 $a_ppps = &$config['ppps']['ppp'];
 
 $iflist = get_configured_interface_with_descr();
@@ -470,7 +463,6 @@ $types = array("select" => gettext("Select"), "ppp" => gettext("PPP"), "pppoe" =
 $serviceproviders_xml = "/usr/local/share/mobile-broadband-provider-info/serviceproviders.xml";
 $serviceproviders_contents = file_get_contents($serviceproviders_xml);
 $serviceproviders_attr = xml2array($serviceproviders_contents, 1, "attr");
-
 $serviceproviders = &$serviceproviders_attr['serviceproviders']['country'];
 
 //print_r($serviceproviders);
diff --git a/src/usr/local/www/interfaces_vlan.php b/src/usr/local/www/interfaces_vlan.php
index ccda74eb5d..b0a53c97e2 100644
--- a/src/usr/local/www/interfaces_vlan.php
+++ b/src/usr/local/www/interfaces_vlan.php
@@ -35,15 +35,8 @@ require_once("interfaces_fast.inc");
 
 global $profile;
 
-if (!is_array($config['vlans'])) {
-	$config['vlans'] = array();
-}
-
-if (!is_array($config['vlans']['vlan'])) {
-	$config['vlans']['vlan'] = array();
-}
-
-$a_vlans = &$config['vlans']['vlan'] ;
+init_config_arr(array('vlans', 'vlan'));
+$a_vlans = &$config['vlans']['vlan'];
 
 if ($_POST['act'] == "del") {
 	if (!isset($_POST['id'])) {
diff --git a/src/usr/local/www/interfaces_vlan_edit.php b/src/usr/local/www/interfaces_vlan_edit.php
index 23ea5a09d4..5dcc34207f 100644
--- a/src/usr/local/www/interfaces_vlan_edit.php
+++ b/src/usr/local/www/interfaces_vlan_edit.php
@@ -32,13 +32,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['vlans'])) {
-	$config['vlans'] = array();
-}
-if (!is_array($config['vlans']['vlan'])) {
-	$config['vlans']['vlan'] = array();
-}
-
+init_config_arr(array('vlans', 'vlan'));
 $a_vlans = &$config['vlans']['vlan'];
 
 $portlist = get_interface_list();
diff --git a/src/usr/local/www/interfaces_wireless.php b/src/usr/local/www/interfaces_wireless.php
index 12e0c27043..f701f1fcf4 100644
--- a/src/usr/local/www/interfaces_wireless.php
+++ b/src/usr/local/www/interfaces_wireless.php
@@ -29,13 +29,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['wireless'])) {
-	$config['wireless'] = array();
-}
-if (!is_array($config['wireless']['clone'])) {
-	$config['wireless']['clone'] = array();
-}
-
+init_config_arr(array('wireless', 'clone'));
 $a_clones = &$config['wireless']['clone'];
 
 function clone_inuse($num) {
diff --git a/src/usr/local/www/interfaces_wireless_edit.php b/src/usr/local/www/interfaces_wireless_edit.php
index b78a71a822..22d88bdd1f 100644
--- a/src/usr/local/www/interfaces_wireless_edit.php
+++ b/src/usr/local/www/interfaces_wireless_edit.php
@@ -29,14 +29,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['wireless'])) {
-	$config['wireless'] = array();
-}
-
-if (!is_array($config['wireless']['clone'])) {
-	$config['wireless']['clone'] = array();
-}
-
+init_config_arr(array('wireless', 'clone'));
 $a_clones = &$config['wireless']['clone'];
 
 function clone_inuse($num) {
diff --git a/src/usr/local/www/load_balancer_monitor.php b/src/usr/local/www/load_balancer_monitor.php
index d8b3433fad..ae55ea5f9e 100644
--- a/src/usr/local/www/load_balancer_monitor.php
+++ b/src/usr/local/www/load_balancer_monitor.php
@@ -30,9 +30,7 @@
 require_once("guiconfig.inc");
 require_once("filter.inc");
 
-if (!is_array($config['load_balancer']['monitor_type'])) {
-	$config['load_balancer']['monitor_type'] = array();
-}
+init_config_arr(array('load_balancer', 'monitor_type'));
 $a_monitor = &$config['load_balancer']['monitor_type'];
 
 $pconfig = $_POST;
diff --git a/src/usr/local/www/load_balancer_monitor_edit.php b/src/usr/local/www/load_balancer_monitor_edit.php
index 8865513e0a..0185c89d6a 100644
--- a/src/usr/local/www/load_balancer_monitor_edit.php
+++ b/src/usr/local/www/load_balancer_monitor_edit.php
@@ -31,10 +31,7 @@ require_once("guiconfig.inc");
 
 $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/load_balancer_monitor.php');
 
-if (!is_array($config['load_balancer']['monitor_type'])) {
-	$config['load_balancer']['monitor_type'] = array();
-}
-
+init_config_arr(array('load_balancer', 'monitor_type'));
 $a_monitor = &$config['load_balancer']['monitor_type'];
 $id = $_REQUEST['id'];
 
diff --git a/src/usr/local/www/load_balancer_pool.php b/src/usr/local/www/load_balancer_pool.php
index ad437c1f47..cd4a3f598a 100644
--- a/src/usr/local/www/load_balancer_pool.php
+++ b/src/usr/local/www/load_balancer_pool.php
@@ -32,10 +32,7 @@ require_once("functions.inc");
 require_once("filter.inc");
 require_once("shaper.inc");
 
-if (!is_array($config['load_balancer']['lbpool'])) {
-	$config['load_balancer']['lbpool'] = array();
-}
-
+init_config_arr(array('load_balancer', 'lbpool'));
 $a_pool = &$config['load_balancer']['lbpool'];
 
 $pconfig = $_POST;
diff --git a/src/usr/local/www/load_balancer_pool_edit.php b/src/usr/local/www/load_balancer_pool_edit.php
index aa639a59ba..539686151f 100644
--- a/src/usr/local/www/load_balancer_pool_edit.php
+++ b/src/usr/local/www/load_balancer_pool_edit.php
@@ -33,16 +33,13 @@ require_once("util.inc");
 
 $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/load_balancer_pool.php');
 
-if (!is_array($config['load_balancer']['lbpool'])) {
-	$config['load_balancer']['lbpool'] = array();
-}
-
+init_config_arr(array('load_balancer', 'lbpool'));
 $a_pool = &$config['load_balancer']['lbpool'];
 
 $id = $_REQUEST['id'];
 
-
 if (isset($id) && $a_pool[$id]) {
+	init_config_arr(array('load_balancer', 'lbpool', $id));
 	$pconfig['name'] = $a_pool[$id]['name'];
 	$pconfig['mode'] = $a_pool[$id]['mode'];
 	$pconfig['descr'] = $a_pool[$id]['descr'];
diff --git a/src/usr/local/www/load_balancer_setting.php b/src/usr/local/www/load_balancer_setting.php
index b563ac4f3c..6592d847d4 100644
--- a/src/usr/local/www/load_balancer_setting.php
+++ b/src/usr/local/www/load_balancer_setting.php
@@ -34,10 +34,7 @@ require_once("filter.inc");
 require_once("shaper.inc");
 require_once("util.inc");
 
-if (!is_array($config['load_balancer']['setting'])) {
-	$config['load_balancer']['setting'] = array();
-}
-
+init_config_arr(array('load_balancer', 'setting'));
 $lbsetting = &$config['load_balancer']['setting'];
 
 if ($_POST) {
diff --git a/src/usr/local/www/load_balancer_virtual_server.php b/src/usr/local/www/load_balancer_virtual_server.php
index faa637f6b5..907b6dd30c 100644
--- a/src/usr/local/www/load_balancer_virtual_server.php
+++ b/src/usr/local/www/load_balancer_virtual_server.php
@@ -33,10 +33,7 @@ require_once("filter.inc");
 require_once("shaper.inc");
 require_once("vslb.inc");
 
-if (!is_array($config['load_balancer']['virtual_server'])) {
-	$config['load_balancer']['virtual_server'] = array();
-}
-
+init_config_arr(array('load_balancer', 'virtual_server'));
 $a_vs = &$config['load_balancer']['virtual_server'];
 
 $pconfig = $_POST;
diff --git a/src/usr/local/www/load_balancer_virtual_server_edit.php b/src/usr/local/www/load_balancer_virtual_server_edit.php
index c6fc400435..c09e26ade5 100644
--- a/src/usr/local/www/load_balancer_virtual_server_edit.php
+++ b/src/usr/local/www/load_balancer_virtual_server_edit.php
@@ -35,15 +35,11 @@ if (isset($_POST['referer'])) {
 	$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/load_balancer_virtual_server.php');
 }
 
-if (!is_array($config['load_balancer']['virtual_server'])) {
-	$config['load_balancer']['virtual_server'] = array();
-}
-
-if (!is_array($config['load_balancer']['lbpool'])) {
-	$config['load_balancer']['lbpool'] = array();
-}
-
+init_config_arr(array('load_balancer', 'virtual_server'));
 $a_vs = &$config['load_balancer']['virtual_server'];
+init_config_arr(array('load_balancer', 'lbpool'));
+$a_pool = &$config['load_balancer']['lbpool'];
+
 $id = $_REQUEST['id'];
 
 if (isset($id) && $a_vs[$id]) {
diff --git a/src/usr/local/www/pkg.php b/src/usr/local/www/pkg.php
index bb39bac829..013f2a41e7 100644
--- a/src/usr/local/www/pkg.php
+++ b/src/usr/local/www/pkg.php
@@ -125,6 +125,7 @@ if ($_REQUEST['act'] == "del") {
 		}
 	}
 
+	init_config_arr(array('installedpackages', xml_safe_fieldname($pkg['name']), 'config'));
 	$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
 
 	if ($a_pkg[$_REQUEST['id']]) {
diff --git a/src/usr/local/www/pkg_edit.php b/src/usr/local/www/pkg_edit.php
index c0c2fcb6f4..ca62125d89 100644
--- a/src/usr/local/www/pkg_edit.php
+++ b/src/usr/local/www/pkg_edit.php
@@ -95,8 +95,9 @@ if ($config['installedpackages'] && !is_array($config['installedpackages'][xml_s
  *  https://redmine.pfsense.org/issues/7624
  *  https://redmine.pfsense.org/issues/476
  */
-if ($config['installedpackages'] &&
-    (count($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']) > 0) &&
+
+init_config_arr(array('installedpackages', xml_safe_fieldname($pkg['name']), 'config'));
+if ((count($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']) > 0) &&
     (empty($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'][0])) &&
     is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'])) {
 	array_shift($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']);
@@ -1102,10 +1103,7 @@ foreach ($pkg['fields']['field'] as $pkga) {
 			$size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
 			$fieldname = $pkga['fieldname'];
 
-			if (!is_array($config['aliases'])) {
-				$config['aliases'] = array();
-			}
-			
+			init_config_arr(array('aliases', 'alias'));
 			$a_aliases = &$config['aliases']['alias'];
 			$addrisfirst = 0;
 			$aliasesaddr = "";
diff --git a/src/usr/local/www/services_acb_settings.php b/src/usr/local/www/services_acb_settings.php
index ce610bd5ed..caf7473087 100644
--- a/src/usr/local/www/services_acb_settings.php
+++ b/src/usr/local/www/services_acb_settings.php
@@ -56,6 +56,8 @@ function index_of_command() {
 }
 
 $croncmd = "/usr/bin/nice -n20 /usr/local/bin/php /usr/local/sbin/execacb.php";
+
+init_config_arr(array('cron', 'item'));
 $a_cron = &$config['cron']['item'];
 $pconfig = $config['system']['acb'];
 
diff --git a/src/usr/local/www/services_captiveportal.php b/src/usr/local/www/services_captiveportal.php
index 8d6abad74b..ccdc6152af 100644
--- a/src/usr/local/www/services_captiveportal.php
+++ b/src/usr/local/www/services_captiveportal.php
@@ -54,11 +54,8 @@ if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+$a_cp = &$config['captiveportal'];
 
 $pgtitle = array(gettext("Services"), gettext("Captive Portal"), $a_cp[$cpzone]['zone'], gettext("Configuration"));
 $pglinks = array("", "services_captiveportal_zones.php", "@self", "@self");
@@ -126,17 +123,11 @@ if ($_REQUEST['act'] == "viewhtml") {
 	exit;
 }
 
-if (!is_array($config['ca'])) {
-	$config['ca'] = array();
-}
-
-$a_ca =& $config['ca'];
-
-if (!is_array($config['cert'])) {
-	$config['cert'] = array();
-}
+init_config_arr(array('ca'));
+$a_ca = &$config['ca'];
 
-$a_cert =& $config['cert'];
+init_config_arr(array('cert'));
+$a_cert = &$config['cert'];
 
 if ($a_cp[$cpzone]) {
 	$cpzoneid = $pconfig['zoneid'] = $a_cp[$cpzone]['zoneid'];
@@ -319,7 +310,8 @@ if ($_POST['save']) {
 	}
 
 	if (!$input_errors) {
-		$newcp =& $a_cp[$cpzone];
+		init_config_arr(array('captiveportal', $cpzone));
+		$newcp = &$a_cp[$cpzone];
 		//$newcp['zoneid'] = $a_cp[$cpzone]['zoneid'];
 		if (empty($newcp['zoneid'])) {
 			$newcp['zoneid'] = 2;
diff --git a/src/usr/local/www/services_captiveportal_filemanager.php b/src/usr/local/www/services_captiveportal_filemanager.php
index 1175bd7a79..d688e57b97 100644
--- a/src/usr/local/www/services_captiveportal_filemanager.php
+++ b/src/usr/local/www/services_captiveportal_filemanager.php
@@ -57,22 +57,14 @@ if (empty($cpzone)) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal', $cpzone, 'element'));
+$a_cp = &$config['captiveportal'];
+$a_element = &$a_cp[$cpzone]['element'];
 
 $pgtitle = array(gettext("Services"), gettext("Captive Portal"), $a_cp[$cpzone]['zone'], gettext("File Manager"));
 $pglinks = array("", "services_captiveportal_zones.php", "services_captiveportal.php?zone=" . $cpzone, "@self");
 $shortcut_section = "captiveportal";
 
-if (!is_array($a_cp[$cpzone]['element'])) {
-	$a_cp[$cpzone]['element'] = array();
-}
-
-$a_element =& $a_cp[$cpzone]['element'];
-
 // Calculate total size of all files
 $total_size = 0;
 for ($i = 0; $i < count($a_element); $i++) {
diff --git a/src/usr/local/www/services_captiveportal_hostname.php b/src/usr/local/www/services_captiveportal_hostname.php
index 9372df7669..b9ba5736b4 100644
--- a/src/usr/local/www/services_captiveportal_hostname.php
+++ b/src/usr/local/www/services_captiveportal_hostname.php
@@ -49,11 +49,9 @@ if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal', $cpzone, 'allowedhostname'));
+$a_cp = &$config['captiveportal'];
+$a_allowedhostnames = &$a_cp[$cpzone]['allowedhostname'];
 
 if (isset($cpzone) && !empty($cpzone) && isset($a_cp[$cpzone]['zoneid'])) {
 	$cpzoneid = $a_cp[$cpzone]['zoneid'];
@@ -64,7 +62,6 @@ $pglinks = array("", "services_captiveportal_zones.php", "services_captiveportal
 $shortcut_section = "captiveportal";
 
 if ($_POST['act'] == "del" && !empty($cpzone)) {
-	$a_allowedhostnames =& $a_cp[$cpzone]['allowedhostname'];
 	if ($a_allowedhostnames[$_POST['id']]) {
 		$ipent = $a_allowedhostnames[$_POST['id']];
 
diff --git a/src/usr/local/www/services_captiveportal_hostname_edit.php b/src/usr/local/www/services_captiveportal_hostname_edit.php
index 99f422b7e4..e2dc716dd3 100644
--- a/src/usr/local/www/services_captiveportal_hostname_edit.php
+++ b/src/usr/local/www/services_captiveportal_hostname_edit.php
@@ -54,11 +54,9 @@ if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal', $cpzone, 'allowedhostname'));
+$a_cp = &$config['captiveportal'];
+$a_allowedhostnames = &$a_cp[$cpzone]['allowedhostname'];
 
 $pgtitle = array(gettext("Services"), gettext("Captive Portal"), $a_cp[$cpzone]['zone'], gettext("Allowed Hostnames"), gettext("Edit"));
 $pglinks = array("", "services_captiveportal_zones.php", "services_captiveportal.php?zone=" . $cpzone, "services_captiveportal_hostname.php?zone=" . $cpzone, "@self");
@@ -66,13 +64,6 @@ $shortcut_section = "captiveportal";
 
 $id = $_REQUEST['id'];
 
-
-if (!is_array($a_cp[$cpzone]['allowedhostname'])) {
-	$a_cp[$cpzone]['allowedhostname'] = array();
-}
-
-$a_allowedhostnames = &$a_cp[$cpzone]['allowedhostname'];
-
 if (isset($id) && $a_allowedhostnames[$id]) {
 	$pconfig['zone'] = $a_allowedhostnames[$id]['zone'];
 	$pconfig['hostname'] = $a_allowedhostnames[$id]['hostname'];
diff --git a/src/usr/local/www/services_captiveportal_ip.php b/src/usr/local/www/services_captiveportal_ip.php
index d55a8d31aa..7140c028a4 100644
--- a/src/usr/local/www/services_captiveportal_ip.php
+++ b/src/usr/local/www/services_captiveportal_ip.php
@@ -46,11 +46,8 @@ if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+$a_cp = &$config['captiveportal'];
 
 if (isset($cpzone) && !empty($cpzone) && isset($a_cp[$cpzone]['zoneid'])) {
 	$cpzoneid = $a_cp[$cpzone]['zoneid'];
@@ -61,7 +58,8 @@ $pglinks = array("", "services_captiveportal_zones.php", "services_captiveportal
 $shortcut_section = "captiveportal";
 
 if ($_POST['act'] == "del" && !empty($cpzone)) {
-	$a_allowedips =& $config['captiveportal'][$cpzone]['allowedip'];
+	init_config_arr(array('captiveportal', $cpzone, 'allowedip'));
+	$a_allowedips = &$config['captiveportal'][$cpzone]['allowedip'];
 
 	if ($a_allowedips[$_POST['id']]) {
 		$ipent = $a_allowedips[$_POST['id']];
diff --git a/src/usr/local/www/services_captiveportal_ip_edit.php b/src/usr/local/www/services_captiveportal_ip_edit.php
index c94bca83da..4256ff3b1f 100644
--- a/src/usr/local/www/services_captiveportal_ip_edit.php
+++ b/src/usr/local/www/services_captiveportal_ip_edit.php
@@ -54,23 +54,15 @@ if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal', $cpzone, 'allowedip'));
+$a_cp = &$config['captiveportal'];
+$a_allowedips = &$config['captiveportal'][$cpzone]['allowedip'];
 
 $pgtitle = array(gettext("Services"), gettext("Captive Portal"), $a_cp[$cpzone]['zone'], gettext("Allowed IP Addresses"), gettext("Edit"));
 $pglinks = array("", "services_captiveportal_zones.php", "services_captiveportal.php?zone=" . $cpzone, "services_captiveportal_ip.php?zone=" . $cpzone, "@self");
 $shortcut_section = "captiveportal";
 $id = $_REQUEST['id'];
 
-if (!is_array($config['captiveportal'][$cpzone]['allowedip'])) {
-	$config['captiveportal'][$cpzone]['allowedip'] = array();
-}
-
-$a_allowedips =& $config['captiveportal'][$cpzone]['allowedip'];
-
 if (isset($id) && $a_allowedips[$id]) {
 	$pconfig['ip'] = $a_allowedips[$id]['ip'];
 	$pconfig['sn'] = $a_allowedips[$id]['sn'];
diff --git a/src/usr/local/www/services_captiveportal_mac.php b/src/usr/local/www/services_captiveportal_mac.php
index b767dc9d39..7698e04d54 100644
--- a/src/usr/local/www/services_captiveportal_mac.php
+++ b/src/usr/local/www/services_captiveportal_mac.php
@@ -47,11 +47,9 @@ if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal', $cpzone, 'passthrumac'));
+$a_cp = &$config['captiveportal'];
+$a_passthrumacs = &$a_cp[$cpzone]['passthrumac'];
 
 $pgtitle = array(gettext("Services"), gettext("Captive Portal"), $a_cp[$cpzone]['zone'], gettext("MACs"));
 $pglinks = array("", "services_captiveportal_zones.php", "services_captiveportal.php?zone=" . $cpzone, "@self");
@@ -81,20 +79,11 @@ if ($_POST['save']) {
 	}
 
 	if ($_POST['postafterlogin']) {
-		if (!is_array($a_passthrumacs)) {
+		if (empty($a_passthrumacs)) {
 			echo gettext("No entry exists yet!") ."\n";
 			exit;
 		}
 
-		if (empty($_POST['zone'])) {
-			echo gettext("Please set the zone on which the operation should be allowed");
-			exit;
-		}
-		if (!is_array($a_cp[$cpzone]['passthrumac'])) {
-			$a_cp[$cpzone]['passthrumac'] = array();
-		}
-		$a_passthrumacs =& $a_cp[$cpzone]['passthrumac'];
-
 		if ($_POST['username']) {
 			$mac = captiveportal_passthrumac_findbyname($_POST['username']);
 			if (!empty($mac)) {
@@ -131,8 +120,6 @@ if ($_POST['save']) {
 }
 
 if ($_POST['act'] == "del") {
-	$a_passthrumacs =& $a_cp[$cpzone]['passthrumac'];
-
 	if ($a_passthrumacs[$_POST['id']]) {
 		$cpzoneid = $a_cp[$cpzone]['zoneid'];
 		$rules = captiveportal_passthrumac_delete_entry($a_passthrumacs[$_POST['id']]);
diff --git a/src/usr/local/www/services_captiveportal_mac_edit.php b/src/usr/local/www/services_captiveportal_mac_edit.php
index c149ec4b68..e6bcdaba7b 100644
--- a/src/usr/local/www/services_captiveportal_mac_edit.php
+++ b/src/usr/local/www/services_captiveportal_mac_edit.php
@@ -57,11 +57,9 @@ if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal', $cpzone, 'passthrumac'));
+$a_cp = &$config['captiveportal'];
+$a_passthrumacs = &$a_cp[$cpzone]['passthrumac'];
 
 $pgtitle = array(gettext("Services"), gettext("Captive Portal"), $a_cp[$cpzone]['zone'], gettext("MACs"), gettext("Edit"));
 $pglinks = array("", "services_captiveportal_zones.php", "services_captiveportal.php?zone=" . $cpzone, "services_captiveportal_mac.php?zone=" . $cpzone, "@self");
@@ -71,12 +69,6 @@ if (is_numericint($_REQUEST['id'])) {
 	$id = $_REQUEST['id'];
 }
 
-if (!is_array($a_cp[$cpzone]['passthrumac'])) {
-	$a_cp[$cpzone]['passthrumac'] = array();
-}
-
-$a_passthrumacs = &$a_cp[$cpzone]['passthrumac'];
-
 if (isset($id) && $a_passthrumacs[$id]) {
 	$pconfig['action'] = $a_passthrumacs[$id]['action'];
 	$pconfig['mac'] = $a_passthrumacs[$id]['mac'];
diff --git a/src/usr/local/www/services_captiveportal_vouchers.php b/src/usr/local/www/services_captiveportal_vouchers.php
index 1c70b97def..b9ba0600aa 100644
--- a/src/usr/local/www/services_captiveportal_vouchers.php
+++ b/src/usr/local/www/services_captiveportal_vouchers.php
@@ -55,15 +55,9 @@ if (empty($cpzone)) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
-
-if (!is_array($config['voucher'])) {
-	$config['voucher'] = array();
-}
+init_config_arr(array('captiveportal'));
+init_config_arr(array('voucher', $cpzone, 'roll'));
+$a_cp = &$config['captiveportal'];
 
 if (empty($a_cp[$cpzone])) {
 	log_error(sprintf(gettext("Submission on captiveportal page with unknown zone parameter: %s"), htmlspecialchars($cpzone)));
diff --git a/src/usr/local/www/services_captiveportal_vouchers_edit.php b/src/usr/local/www/services_captiveportal_vouchers_edit.php
index d8786c0695..b69a0d1271 100644
--- a/src/usr/local/www/services_captiveportal_vouchers_edit.php
+++ b/src/usr/local/www/services_captiveportal_vouchers_edit.php
@@ -41,28 +41,17 @@ if (empty($cpzone) || empty($config['captiveportal'][$cpzone])) {
 	exit;
 }
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+init_config_arr(array('voucher', $cpzone, 'roll'));
+$a_cp = &$config['captiveportal'];
+$a_roll = &$config['voucher'][$cpzone]['roll'];
 
 $pgtitle = array(gettext("Services"), gettext("Captive Portal"), $a_cp[$cpzone]['zone'], gettext("Vouchers"), gettext("Edit"));
 $pglinks = array("", "services_captiveportal_zones.php", "services_captiveportal.php?zone=" . $cpzone, "services_captiveportal_vouchers.php?zone=" . $cpzone, "@self");
 $shortcut_section = "captiveportal-vouchers";
 
-if (!is_array($config['voucher'])) {
-	$config['voucher'] = array();
-}
-
-if (!is_array($config['voucher'][$cpzone]['roll'])) {
-	$config['voucher'][$cpzone]['roll'] = array();
-}
-
-$a_roll = &$config['voucher'][$cpzone]['roll'];
 $id = $_REQUEST['id'];
 
-
 if (isset($id) && $a_roll[$id]) {
 	$pconfig['zone'] = $a_roll[$id]['zone'];
 	$pconfig['number'] = $a_roll[$id]['number'];
diff --git a/src/usr/local/www/services_captiveportal_zones.php b/src/usr/local/www/services_captiveportal_zones.php
index b68f94f701..44473262b2 100644
--- a/src/usr/local/www/services_captiveportal_zones.php
+++ b/src/usr/local/www/services_captiveportal_zones.php
@@ -35,9 +35,7 @@ require_once("captiveportal.inc");
 global $cpzone;
 global $cpzoneid;
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
+init_config_arr(array('captiveportal'));
 $a_cp = &$config['captiveportal'];
 
 if ($_POST['act'] == "del" && !empty($_POST['zone'])) {
diff --git a/src/usr/local/www/services_captiveportal_zones_edit.php b/src/usr/local/www/services_captiveportal_zones_edit.php
index 6294ffd21f..04c42d39ec 100644
--- a/src/usr/local/www/services_captiveportal_zones_edit.php
+++ b/src/usr/local/www/services_captiveportal_zones_edit.php
@@ -36,11 +36,8 @@ $pgtitle = array(gettext("Services"), gettext("Captive Portal"), gettext("Add Zo
 $pglinks = array("", "services_captiveportal_zones.php", "@self");
 $shortcut_section = "captiveportal";
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+$a_cp = &$config['captiveportal'];
 
 if ($_POST['Submit']) {
 	unset($input_errors);
diff --git a/src/usr/local/www/services_checkip.php b/src/usr/local/www/services_checkip.php
index 5c4707dd67..a6dd03079d 100644
--- a/src/usr/local/www/services_checkip.php
+++ b/src/usr/local/www/services_checkip.php
@@ -28,14 +28,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['checkipservices'])) {
-	$config['checkipservices'] = array();
-}
-
-if (!is_array($config['checkipservices']['checkipservice'])) {
-	$config['checkipservices']['checkipservice'] = array();
-}
-
+init_config_arr(array('checkipservices', 'checkipservice'));
 $a_checkipservice = &$config['checkipservices']['checkipservice'];
 
 $dirty = false;
diff --git a/src/usr/local/www/services_checkip_edit.php b/src/usr/local/www/services_checkip_edit.php
index c686065bdd..426653404e 100644
--- a/src/usr/local/www/services_checkip_edit.php
+++ b/src/usr/local/www/services_checkip_edit.php
@@ -28,14 +28,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['checkipservices'])) {
-	$config['checkipservices'] = array();
-}
-
-if (!is_array($config['checkipservices']['checkipservice'])) {
-	$config['checkipservices']['checkipservice'] = array();
-}
-
+init_config_arr(array('checkipservices', 'checkipservice'));
 $a_checkip = &$config['checkipservices']['checkipservice'];
 
 if (is_numericint($_REQUEST['id'])) {
diff --git a/src/usr/local/www/services_dhcp.php b/src/usr/local/www/services_dhcp.php
index e3c26cc1e3..8d370abebf 100644
--- a/src/usr/local/www/services_dhcp.php
+++ b/src/usr/local/www/services_dhcp.php
@@ -107,10 +107,7 @@ if (is_array($config['dhcpd'][$if])) {
 		exit;
 	}
 
-	if (!is_array($config['dhcpd'][$if]['pool'])) {
-		$config['dhcpd'][$if]['pool'] = array();
-	}
-
+	init_config_arr(array('dhcpd', $if, 'pool'));
 	$a_pools = &$config['dhcpd'][$if]['pool'];
 
 	if (is_numeric($pool) && $a_pools[$pool]) {
@@ -121,10 +118,7 @@ if (is_array($config['dhcpd'][$if])) {
 		$dhcpdconf = &$config['dhcpd'][$if];
 	}
 
-	if (!is_array($config['dhcpd'][$if]['staticmap'])) {
-		$dhcpdconf['staticmap'] = array();
-	}
-
+	init_config_arr(array('dhcpd', $if, 'staticmap'));
 	$a_maps = &$config['dhcpd'][$if]['staticmap'];
 }
 
diff --git a/src/usr/local/www/services_dhcp_edit.php b/src/usr/local/www/services_dhcp_edit.php
index 1423171e45..90ec954199 100644
--- a/src/usr/local/www/services_dhcp_edit.php
+++ b/src/usr/local/www/services_dhcp_edit.php
@@ -56,27 +56,12 @@ if (!$if) {
 	exit;
 }
 
-if (!is_array($config['dhcpd'])) {
-	$config['dhcpd'] = array();
-}
-
-if (!is_array($config['dhcpd'][$if])) {
-	$config['dhcpd'][$if] = array();
-}
-
-if (!is_array($config['dhcpd'][$if]['staticmap'])) {
-	$config['dhcpd'][$if]['staticmap'] = array();
-}
-
-if (!is_array($config['dhcpd'][$if]['pool'])) {
-	$config['dhcpd'][$if]['pool'] = array();
-}
-
+init_config_arr(array('dhcpd', $if, 'staticmap'));
+init_config_arr(array('dhcpd', $if, 'pool'));
+$a_maps = &$config['dhcpd'][$if]['staticmap'];
 $a_pools = &$config['dhcpd'][$if]['pool'];
-
 $static_arp_enabled=isset($config['dhcpd'][$if]['staticarp']);
 $netboot_enabled=isset($config['dhcpd'][$if]['netboot']);
-$a_maps = &$config['dhcpd'][$if]['staticmap'];
 $ifcfgip = get_interface_ip($if);
 $ifcfgsn = get_interface_subnet($if);
 $ifcfgdescr = convert_friendly_interface_to_friendly_descr($if);
diff --git a/src/usr/local/www/services_dhcpv6.php b/src/usr/local/www/services_dhcpv6.php
index 752f844a93..1c6b10d05b 100644
--- a/src/usr/local/www/services_dhcpv6.php
+++ b/src/usr/local/www/services_dhcpv6.php
@@ -160,6 +160,7 @@ if (is_array($config['dhcpdv6'][$if])) {
 	if (!is_array($config['dhcpdv6'][$if]['staticmap'])) {
 		$config['dhcpdv6'][$if]['staticmap'] = array();
 	}
+	init_config_arr(array('dhcpdv6', $if, 'staticmap'));
 	$a_maps = &$config['dhcpdv6'][$if]['staticmap'];
 }
 
diff --git a/src/usr/local/www/services_dhcpv6_edit.php b/src/usr/local/www/services_dhcpv6_edit.php
index de7ba1cfc4..d30f103c8b 100644
--- a/src/usr/local/www/services_dhcpv6_edit.php
+++ b/src/usr/local/www/services_dhcpv6_edit.php
@@ -57,16 +57,7 @@ if (!$if) {
 	exit;
 }
 
-if (!is_array($config['dhcpdv6'])) {
-	$config['dhcpdv6'] = array();
-}
-if (!is_array($config['dhcpdv6'][$if])) {
-	$config['dhcpdv6'][$if] = array();
-}
-if (!is_array($config['dhcpdv6'][$if]['staticmap'])) {
-	$config['dhcpdv6'][$if]['staticmap'] = array();
-}
-
+init_config_arr(array('dhcpdv6', $if, 'staticmap'));
 $netboot_enabled = isset($config['dhcpdv6'][$if]['netboot']);
 $a_maps = &$config['dhcpdv6'][$if]['staticmap'];
 $ifcfgipv6 = get_interface_ipv6($if);
diff --git a/src/usr/local/www/services_dnsmasq.php b/src/usr/local/www/services_dnsmasq.php
index 53b812f6c0..b5e561cb44 100644
--- a/src/usr/local/www/services_dnsmasq.php
+++ b/src/usr/local/www/services_dnsmasq.php
@@ -85,14 +85,6 @@ if (!empty($config['dnsmasq']['interface'])) {
 	$pconfig['interface'] = array();
 }
 
-if (!is_array($config['dnsmasq']['hosts'])) {
-	$config['dnsmasq']['hosts'] = array();
-}
-
-if (!is_array($config['dnsmasq']['domainoverrides'])) {
-	$config['dnsmasq']['domainoverrides'] = array();
-}
-
 init_config_arr(array('dnsmasq', 'hosts'));
 $a_hosts = &$config['dnsmasq']['hosts'];
 
diff --git a/src/usr/local/www/services_dnsmasq_domainoverride_edit.php b/src/usr/local/www/services_dnsmasq_domainoverride_edit.php
index 8ced019de9..dc2836810d 100644
--- a/src/usr/local/www/services_dnsmasq_domainoverride_edit.php
+++ b/src/usr/local/www/services_dnsmasq_domainoverride_edit.php
@@ -33,10 +33,6 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['dnsmasq']['domainoverrides'])) {
-	   $config['dnsmasq']['domainoverrides'] = array();
-}
-
 init_config_arr(array('dnsmasq', 'domainoverrides'));
 $a_domainOverrides = &$config['dnsmasq']['domainoverrides'];
 
diff --git a/src/usr/local/www/services_dnsmasq_edit.php b/src/usr/local/www/services_dnsmasq_edit.php
index 34daef57cc..0d2afb59e9 100644
--- a/src/usr/local/www/services_dnsmasq_edit.php
+++ b/src/usr/local/www/services_dnsmasq_edit.php
@@ -33,10 +33,6 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['dnsmasq']['hosts'])) {
-	$config['dnsmasq']['hosts'] = array();
-}
-
 init_config_arr(array('dnsmasq', 'hosts'));
 $a_hosts = &$config['dnsmasq']['hosts'];
 
diff --git a/src/usr/local/www/services_dyndns.php b/src/usr/local/www/services_dyndns.php
index ba13adf749..a952ac1d1f 100644
--- a/src/usr/local/www/services_dyndns.php
+++ b/src/usr/local/www/services_dyndns.php
@@ -28,14 +28,7 @@
 
 require_once("guiconfig.inc");
 
-if(!is_array($config['dyndnses'])){
-	$config['dyndnses'] = array();
-}
-
-if (!is_array($config['dyndnses']['dyndns'])) {
-	$config['dyndnses']['dyndns'] = array();
-}
-
+init_config_arr(array('dyndnses', 'dyndns'));
 $a_dyndns = &$config['dyndnses']['dyndns'];
 global $dyndns_split_domain_types;
 
diff --git a/src/usr/local/www/services_dyndns_edit.php b/src/usr/local/www/services_dyndns_edit.php
index 9d051705f0..846f32ba4a 100644
--- a/src/usr/local/www/services_dyndns_edit.php
+++ b/src/usr/local/www/services_dyndns_edit.php
@@ -41,14 +41,7 @@ function is_dyndns_username($uname) {
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['dyndnses'])) {
-	$config['dyndnses'] = array();
-}
-
-if (!is_array($config['dyndnses']['dyndns'])) {
-	$config['dyndnses']['dyndns'] = array();
-}
-
+init_config_arr(array('dyndnses', 'dyndns'));
 $a_dyndns = &$config['dyndnses']['dyndns'];
 
 $id = $_REQUEST['id'];
diff --git a/src/usr/local/www/services_igmpproxy.php b/src/usr/local/www/services_igmpproxy.php
index a82c055060..0271436e82 100644
--- a/src/usr/local/www/services_igmpproxy.php
+++ b/src/usr/local/www/services_igmpproxy.php
@@ -32,15 +32,9 @@
 
 require_once("guiconfig.inc");
 
-if(!is_array($config['igmpproxy'])){
-	$config['igmpproxy'] = array();
-}
-
-if (!is_array($config['igmpproxy']['igmpentry'])) {
-	$config['igmpproxy']['igmpentry'] = array();
-}
-
 //igmpproxy_sort();
+
+init_config_arr(array('igmpproxy', 'igmpentry'));
 $a_igmpproxy = &$config['igmpproxy']['igmpentry'];
 
 if ($_POST['apply']) {
diff --git a/src/usr/local/www/services_igmpproxy_edit.php b/src/usr/local/www/services_igmpproxy_edit.php
index c816173b19..943c0b1d2d 100644
--- a/src/usr/local/www/services_igmpproxy_edit.php
+++ b/src/usr/local/www/services_igmpproxy_edit.php
@@ -35,15 +35,9 @@ $pglinks = array("", "services_igmpproxy.php", "@self");
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['igmpproxy'])) {
-	$config['igmpproxy'] = array();
-}
-
-if (!is_array($config['igmpproxy']['igmpentry'])) {
-	$config['igmpproxy']['igmpentry'] = array();
-}
-
 //igmpproxy_sort();
+
+init_config_arr(array('igmpproxy', 'igmpentry'));
 $a_igmpproxy = &$config['igmpproxy']['igmpentry'];
 
 if (is_numericint($_REQUEST['id'])) {
diff --git a/src/usr/local/www/services_ntpd.php b/src/usr/local/www/services_ntpd.php
index 27a14de788..c7b851d7c9 100644
--- a/src/usr/local/www/services_ntpd.php
+++ b/src/usr/local/www/services_ntpd.php
@@ -179,6 +179,7 @@ function build_interface_list() {
 	return($iflist);
 }
 
+init_config_arr(array('ntpd'));
 $pconfig = &$config['ntpd'];
 if (empty($pconfig['interface'])) {
 	$pconfig['interface'] = array();
diff --git a/src/usr/local/www/services_ntpd_acls.php b/src/usr/local/www/services_ntpd_acls.php
index 55746f7d6e..748cd4da90 100644
--- a/src/usr/local/www/services_ntpd_acls.php
+++ b/src/usr/local/www/services_ntpd_acls.php
@@ -170,6 +170,7 @@ if ($_POST) {
 	}
 }
 
+init_config_arr(array('ntpd'));
 $pconfig = &$config['ntpd'];
 
 $pgtitle = array(gettext("Services"), gettext("NTP"), gettext("ACLs"));
diff --git a/src/usr/local/www/services_ntpd_gps.php b/src/usr/local/www/services_ntpd_gps.php
index 3e26012232..056343ac73 100644
--- a/src/usr/local/www/services_ntpd_gps.php
+++ b/src/usr/local/www/services_ntpd_gps.php
@@ -306,6 +306,7 @@ function build_nmea_list() {
 	return($nmealist);
 }
 
+init_config_arr(array('ntpd', 'gps'));
 $pconfig = &$config['ntpd']['gps'];
 $pgtitle = array(gettext("Services"), gettext("NTP"), gettext("Serial GPS"));
 $pglinks = array("", "services_ntpd.php", "@self");
diff --git a/src/usr/local/www/services_ntpd_pps.php b/src/usr/local/www/services_ntpd_pps.php
index 015b94145f..3895861eb3 100644
--- a/src/usr/local/www/services_ntpd_pps.php
+++ b/src/usr/local/www/services_ntpd_pps.php
@@ -97,6 +97,7 @@ if ($_POST) {
 	}
 }
 
+init_config_arr(array('ntpd', 'pps'));
 $pconfig = &$config['ntpd']['pps'];
 
 $pgtitle = array(gettext("Services"), gettext("NTP"), gettext("PPS"));
diff --git a/src/usr/local/www/services_pppoe.php b/src/usr/local/www/services_pppoe.php
index 26e71bba38..b52f66b51d 100644
--- a/src/usr/local/www/services_pppoe.php
+++ b/src/usr/local/www/services_pppoe.php
@@ -30,14 +30,7 @@ require_once("guiconfig.inc");
 require_once("filter.inc");
 require_once("vpn.inc");
 
-if (!is_array($config['pppoes'])) {
-	$config['pppoes'] = array();
-}
-
-if (!is_array($config['pppoes']['pppoe'])) {
-	$config['pppoes']['pppoe'] = array();
-}
-
+init_config_arr(array('pppoes', 'pppoe'));
 $a_pppoes = &$config['pppoes']['pppoe'];
 
 
diff --git a/src/usr/local/www/services_pppoe_edit.php b/src/usr/local/www/services_pppoe_edit.php
index a4f781b881..666f892bcf 100644
--- a/src/usr/local/www/services_pppoe_edit.php
+++ b/src/usr/local/www/services_pppoe_edit.php
@@ -46,10 +46,7 @@ function vpn_pppoe_get_id() {
 	return $vpnid;
 }
 
-if (!is_array($config['pppoes']['pppoe'])) {
-	$config['pppoes']['pppoe'] = array();
-}
-
+init_config_arr(array('pppoes', 'pppoe'));
 $a_pppoes = &$config['pppoes']['pppoe'];
 
 if (is_numericint($_REQUEST['id'])) {
diff --git a/src/usr/local/www/services_rfc2136.php b/src/usr/local/www/services_rfc2136.php
index 77e31a2619..6774031655 100644
--- a/src/usr/local/www/services_rfc2136.php
+++ b/src/usr/local/www/services_rfc2136.php
@@ -28,14 +28,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['dnsupdates'])) {
-	$config['dnsupdates'] = array();
-}
-
-if (!is_array($config['dnsupdates']['dnsupdate'])) {
-	$config['dnsupdates']['dnsupdate'] = array();
-}
-
+init_config_arr(array('dnsupdates', 'dnsupdate'));
 $a_rfc2136 = &$config['dnsupdates']['dnsupdate'];
 
 if ($_POST['act'] == "del") {
diff --git a/src/usr/local/www/services_rfc2136_edit.php b/src/usr/local/www/services_rfc2136_edit.php
index 893110c3bb..c2d339c903 100644
--- a/src/usr/local/www/services_rfc2136_edit.php
+++ b/src/usr/local/www/services_rfc2136_edit.php
@@ -37,14 +37,7 @@ $tsig_key_algos = array(
 	'hmac-sha512' => 'HMAC-SHA512 (most secure)',
 );
 
-if (!is_array($config['dnsupdates'])) {
-	$config['dnsupdates'] = array();
-}
-
-if (!is_array($config['dnsupdates']['dnsupdate'])) {
-	$config['dnsupdates']['dnsupdate'] = array();
-}
-
+init_config_arr(array('dnsupdates', 'dnsupdate'));
 $a_rfc2136 = &$config['dnsupdates']['dnsupdate'];
 
 if (is_numericint($_REQUEST['id'])) {
diff --git a/src/usr/local/www/services_unbound.php b/src/usr/local/www/services_unbound.php
index 18465c2113..ceeb7b096d 100644
--- a/src/usr/local/www/services_unbound.php
+++ b/src/usr/local/www/services_unbound.php
@@ -32,22 +32,10 @@ require_once("unbound.inc");
 require_once("pfsense-utils.inc");
 require_once("system.inc");
 
-if (!is_array($config['unbound'])) {
-	$config['unbound'] = array();
-}
-
-$a_unboundcfg =& $config['unbound'];
-
-if (!is_array($a_unboundcfg['hosts'])) {
-	$a_unboundcfg['hosts'] = array();
-}
-
-$a_hosts =& $a_unboundcfg['hosts'];
-
-if (!is_array($a_unboundcfg['domainoverrides'])) {
-	$a_unboundcfg['domainoverrides'] = array();
-}
-
+init_config_arr(array('unbound', 'hosts'));
+init_config_arr(array('unbound', 'domainoverrides'));
+$a_unboundcfg = &$config['unbound'];
+$a_hosts = &$a_unboundcfg['hosts'];
 $a_domainOverrides = &$a_unboundcfg['domainoverrides'];
 
 if (isset($a_unboundcfg['enable'])) {
@@ -98,7 +86,8 @@ if (empty($a_unboundcfg['system_domain_local_zone_type'])) {
 	$pconfig['system_domain_local_zone_type'] = $a_unboundcfg['system_domain_local_zone_type'];
 }
 
-$a_cert =& $config['cert'];
+init_config_arr(array('cert'));
+$a_cert = &$config['cert'];
 $certs_available = false;
 
 if (is_array($a_cert) && count($a_cert)) {
diff --git a/src/usr/local/www/services_unbound_acls.php b/src/usr/local/www/services_unbound_acls.php
index 00541d8eed..c4722f6290 100644
--- a/src/usr/local/www/services_unbound_acls.php
+++ b/src/usr/local/www/services_unbound_acls.php
@@ -31,10 +31,7 @@ require_once("guiconfig.inc");
 require_once("pfsense-utils.inc");
 require_once("unbound.inc");
 
-if (!is_array($config['unbound']['acls'])) {
-	$config['unbound']['acls'] = array();
-}
-
+init_config_arr(array('unbound', 'acls'));
 $a_acls = &$config['unbound']['acls'];
 
 $id = $_REQUEST['id'];
diff --git a/src/usr/local/www/services_unbound_domainoverride_edit.php b/src/usr/local/www/services_unbound_domainoverride_edit.php
index 845054191c..41f80ec207 100644
--- a/src/usr/local/www/services_unbound_domainoverride_edit.php
+++ b/src/usr/local/www/services_unbound_domainoverride_edit.php
@@ -34,10 +34,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['unbound']['domainoverrides'])) {
-	$config['unbound']['domainoverrides'] = array();
-}
-
+init_config_arr(array('unbound', 'domainoverrides'));
 $a_domainOverrides = &$config['unbound']['domainoverrides'];
 $id = $_REQUEST['id'];
 
diff --git a/src/usr/local/www/services_unbound_host_edit.php b/src/usr/local/www/services_unbound_host_edit.php
index df69a1efdf..53b106e208 100644
--- a/src/usr/local/www/services_unbound_host_edit.php
+++ b/src/usr/local/www/services_unbound_host_edit.php
@@ -48,10 +48,7 @@ function hosts_sort() {
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['unbound']['hosts'])) {
-	$config['unbound']['hosts'] = array();
-}
-
+init_config_arr(array('unbound', 'hosts'));
 $a_hosts = &$config['unbound']['hosts'];
 $id = $_REQUEST['id'];
 
diff --git a/src/usr/local/www/services_wol.php b/src/usr/local/www/services_wol.php
index 1280acf4c9..97ecb38054 100644
--- a/src/usr/local/www/services_wol.php
+++ b/src/usr/local/www/services_wol.php
@@ -32,14 +32,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['wol'])) {
-	$config['wol'] = array();
-}
-
-if (!is_array($config['wol']['wolentry'])) {
-	$config['wol']['wolentry'] = array();
-}
-
+init_config_arr(array('wol', 'wolentry'));
 $a_wol = &$config['wol']['wolentry'];
 
 if ($_REQUEST['wakeall'] != "") {
diff --git a/src/usr/local/www/services_wol_edit.php b/src/usr/local/www/services_wol_edit.php
index bd20455d3e..31ad41450d 100644
--- a/src/usr/local/www/services_wol_edit.php
+++ b/src/usr/local/www/services_wol_edit.php
@@ -42,14 +42,7 @@ function wol_sort() {
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['wol'])) {
-	$config['wol'] = array();
-}
-
-if (!is_array($config['wol']['wolentry'])) {
-	$config['wol']['wolentry'] = array();
-}
-
+init_config_arr(array('wol', 'wolentry'));
 $a_wol = &$config['wol']['wolentry'];
 
 if (is_numericint($_REQUEST['id'])) {
diff --git a/src/usr/local/www/status_captiveportal.php b/src/usr/local/www/status_captiveportal.php
index cfcab939a8..bdfd441f5a 100644
--- a/src/usr/local/www/status_captiveportal.php
+++ b/src/usr/local/www/status_captiveportal.php
@@ -117,11 +117,8 @@ function print_details($cpent) {
 
 $cpzone = strtolower($_REQUEST['zone']);
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+$a_cp = &$config['captiveportal'];
 
 if (count($a_cp) == 1) {
 	$cpzone = current(array_keys($a_cp));
diff --git a/src/usr/local/www/status_captiveportal_expire.php b/src/usr/local/www/status_captiveportal_expire.php
index 05e2f655ca..b96100cd15 100644
--- a/src/usr/local/www/status_captiveportal_expire.php
+++ b/src/usr/local/www/status_captiveportal_expire.php
@@ -40,7 +40,8 @@ if (!is_array($config['captiveportal'])) {
 	$config['captiveportal'] = array();
 }
 
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+$a_cp = &$config['captiveportal'];
 
 /* If the zone does not exist, do not display the invalid zone */
 if (!array_key_exists($cpzone, $a_cp)) {
diff --git a/src/usr/local/www/status_captiveportal_test.php b/src/usr/local/www/status_captiveportal_test.php
index 3e5bd891ec..26a707501f 100644
--- a/src/usr/local/www/status_captiveportal_test.php
+++ b/src/usr/local/www/status_captiveportal_test.php
@@ -36,11 +36,8 @@ require_once("voucher.inc");
 
 $cpzone = strtolower($_REQUEST['zone']);
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+$a_cp = &$config['captiveportal'];
 
 /* If the zone does not exist, do not display the invalid zone */
 if (!array_key_exists($cpzone, $a_cp)) {
diff --git a/src/usr/local/www/status_captiveportal_voucher_rolls.php b/src/usr/local/www/status_captiveportal_voucher_rolls.php
index 2219c8daa6..58fd1fc306 100644
--- a/src/usr/local/www/status_captiveportal_voucher_rolls.php
+++ b/src/usr/local/www/status_captiveportal_voucher_rolls.php
@@ -36,11 +36,8 @@ require_once("voucher.inc");
 
 $cpzone = strtolower($_REQUEST['zone']);
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+$a_cp = &$config['captiveportal'];
 
 /* If the zone does not exist, do not display the invalid zone */
 if (!array_key_exists($cpzone, $a_cp)) {
@@ -60,6 +57,7 @@ if (!is_array($config['voucher'][$cpzone]['roll'])) {
 	$config['voucher'][$cpzone]['roll'] = array();
 }
 
+init_config_arr(array('voucher', $cpzone, 'roll'));
 $a_roll = &$config['voucher'][$cpzone]['roll'];
 
 include("head.inc");
diff --git a/src/usr/local/www/status_captiveportal_vouchers.php b/src/usr/local/www/status_captiveportal_vouchers.php
index e399426913..91be0ff6df 100644
--- a/src/usr/local/www/status_captiveportal_vouchers.php
+++ b/src/usr/local/www/status_captiveportal_vouchers.php
@@ -36,11 +36,8 @@ require_once("voucher.inc");
 
 $cpzone = strtolower($_REQUEST['zone']);
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+$a_cp = &$config['captiveportal'];
 
 /* If the zone does not exist, do not display the invalid zone */
 if (!array_key_exists($cpzone, $a_cp)) {
diff --git a/src/usr/local/www/status_carp.php b/src/usr/local/www/status_carp.php
index 680ca366f1..7c350e6e0c 100644
--- a/src/usr/local/www/status_carp.php
+++ b/src/usr/local/www/status_carp.php
@@ -57,36 +57,31 @@ if ($status != 0 && $_POST['carp_maintenancemode'] != "") {
 }
 
 if ($_POST['disablecarp'] != "") {
+	init_config_arr(array('virtualip', 'vip'));
+	$viparr = &$config['virtualip']['vip'];
 	if ($status != 0) {
 		set_single_sysctl('net.inet.carp.allow', '0');
-		if (is_array($config['virtualip']['vip'])) {
-			$viparr = &$config['virtualip']['vip'];
-			foreach ($viparr as $vip) {
-				if ($vip['mode'] != "carp" && $vip['mode'] != "ipalias")
-					continue;
-				if ($vip['mode'] == "ipalias" && substr($vip['interface'], 0, 4) != "_vip")
-					continue;
-
-				interface_vip_bring_down($vip);
-			}
+		foreach ($viparr as $vip) {
+			if ($vip['mode'] != "carp" && $vip['mode'] != "ipalias")
+				continue;
+			if ($vip['mode'] == "ipalias" && substr($vip['interface'], 0, 4) != "_vip")
+				continue;
+			interface_vip_bring_down($vip);
 		}
 		$savemsg = sprintf(gettext("%s IPs have been disabled. Please note that disabling does not survive a reboot and some configuration changes will re-enable."), $carp_counter);
 		$status = 0;
 	} else {
 		$savemsg = gettext("CARP has been enabled.");
-		if (is_array($config['virtualip']['vip'])) {
-			$viparr = &$config['virtualip']['vip'];
-			foreach ($viparr as $vip) {
-				switch ($vip['mode']) {
-					case "carp":
-						interface_carp_configure($vip);
-						break;
-					case 'ipalias':
-						if (substr($vip['interface'], 0, 4) == "_vip") {
-							interface_ipalias_configure($vip);
-						}
-						break;
-				}
+		foreach ($viparr as $vip) {
+			switch ($vip['mode']) {
+				case "carp":
+					interface_carp_configure($vip);
+					break;
+				case 'ipalias':
+					if (substr($vip['interface'], 0, 4) == "_vip") {
+						interface_ipalias_configure($vip);
+					}
+					break;
 			}
 		}
 		interfaces_sync_setup();
diff --git a/src/usr/local/www/status_ipsec.php b/src/usr/local/www/status_ipsec.php
index 15226871bb..61b567dbbb 100644
--- a/src/usr/local/www/status_ipsec.php
+++ b/src/usr/local/www/status_ipsec.php
@@ -35,13 +35,7 @@ require_once("ipsec.inc");
 
 global $g;
 
-if(!is_array($config['ipsec'])){
-	$config['ipsec'] = array();
-}
-
-if (!is_array($config['ipsec']['phase1'])) {
-	$config['ipsec']['phase1'] = array();
-}
+init_config_arr(array('ipsec', 'phase1'));
 
 // If this is just an AJAX call to update the table body, just generate the body and quit
 if ($_REQUEST['ajax']) {
diff --git a/src/usr/local/www/status_lb_pool.php b/src/usr/local/www/status_lb_pool.php
index e44db8fa6f..88bbb961e1 100644
--- a/src/usr/local/www/status_lb_pool.php
+++ b/src/usr/local/www/status_lb_pool.php
@@ -39,10 +39,7 @@ require_once("vslb.inc");
 
 define('COLOR', true);
 
-if (!is_array($config['load_balancer']['lbpool'])) {
-	$config['load_balancer']['lbpool'] = array();
-}
-
+init_config_arr(array('load_balancer', 'lbpool'));
 $a_pool = &$config['load_balancer']['lbpool'];
 
 $lb_logfile = "{$g['varlog_path']}/relayd.log";
diff --git a/src/usr/local/www/status_lb_vs.php b/src/usr/local/www/status_lb_vs.php
index 55ac64760d..1636cef42f 100644
--- a/src/usr/local/www/status_lb_vs.php
+++ b/src/usr/local/www/status_lb_vs.php
@@ -32,14 +32,11 @@ define('COLOR', true);
 require_once("guiconfig.inc");
 require_once("vslb.inc");
 
-if (!is_array($config['load_balancer']['lbpool'])) {
-	$config['load_balancer']['lbpool'] = array();
-}
-if (!is_array($config['load_balancer']['virtual_server'])) {
-	$config['load_balancer']['virtual_server'] = array();
-}
+init_config_arr(array('load_balancer', 'virtual_server'));
 $a_vs = &$config['load_balancer']['virtual_server'];
+init_config_arr(array('load_balancer', 'lbpool'));
 $a_pool = &$config['load_balancer']['lbpool'];
+
 $rdr_a = get_lb_redirects();
 
 $pgtitle = array(gettext("Status"), gettext("Load Balancer"), gettext("Virtual Servers"));
diff --git a/src/usr/local/www/system_advanced_admin.php b/src/usr/local/www/system_advanced_admin.php
index d28bd1dc18..1ecbef46d1 100644
--- a/src/usr/local/www/system_advanced_admin.php
+++ b/src/usr/local/www/system_advanced_admin.php
@@ -66,7 +66,8 @@ $pconfig['sshguard_blocktime'] = $config['system']['sshguard_blocktime'] ?? '';
 $pconfig['sshguard_detection_time'] = $config['system']['sshguard_detection_time'] ?? '';
 $pconfig['sshguard_whitelist'] = $config['system']['sshguard_whitelist'] ?? '';
 
-$a_cert =& $config['cert'];
+init_config_arr(array('cert'));
+$a_cert = &$config['cert'];
 $certs_available = false;
 
 if (is_array($a_cert) && count($a_cert)) {
diff --git a/src/usr/local/www/system_advanced_sysctl.php b/src/usr/local/www/system_advanced_sysctl.php
index 54c43acc48..5496cb82e0 100644
--- a/src/usr/local/www/system_advanced_sysctl.php
+++ b/src/usr/local/www/system_advanced_sysctl.php
@@ -34,13 +34,7 @@
 require_once("guiconfig.inc");
 require_once("pfsense-utils.inc");
 
-if (!is_array($config['sysctl'])) {
-	$config['sysctl'] = array();
-}
-if (!is_array($config['sysctl']['item'])) {
-	$config['sysctl']['item'] = array();
-}
-
+init_config_arr(array('sysctl', 'item'));
 $a_tunable = &$config['sysctl']['item'];
 $tunables = system_get_sysctls();
 
diff --git a/src/usr/local/www/system_authservers.php b/src/usr/local/www/system_authservers.php
index d1443579a2..9ed0e7b5d1 100644
--- a/src/usr/local/www/system_authservers.php
+++ b/src/usr/local/www/system_authservers.php
@@ -105,12 +105,8 @@ if (!is_array($config['system']['authserver'])) {
 
 $a_server = array_values(auth_get_authserver_list());
 
-
-if (!is_array($config['ca'])) {
-	$config['ca'] = array();
-}
-
-$a_ca =& $config['ca'];
+init_config_arr(array('ca'));
+$a_ca = &$config['ca'];
 
 $act = $_REQUEST['act'];
 
diff --git a/src/usr/local/www/system_camanager.php b/src/usr/local/www/system_camanager.php
index f8221ea712..9655ce1439 100644
--- a/src/usr/local/www/system_camanager.php
+++ b/src/usr/local/www/system_camanager.php
@@ -43,23 +43,14 @@ if (isset($_REQUEST['id']) && is_numericint($_REQUEST['id'])) {
 	$id = $_REQUEST['id'];
 }
 
-if (!is_array($config['ca'])) {
-	$config['ca'] = array();
-}
-
-$a_ca =& $config['ca'];
-
-if (!is_array($config['cert'])) {
-	$config['cert'] = array();
-}
-
-$a_cert =& $config['cert'];
+init_config_arr(array('ca'));
+$a_ca = &$config['ca'];
 
-if (!is_array($config['crl'])) {
-	$config['crl'] = array();
-}
+init_config_arr(array('cert'));
+$a_cert = &$config['cert'];
 
-$a_crl =& $config['crl'];
+init_config_arr(array('crl'));
+$a_crl = &$config['crl'];
 
 if ($_REQUEST['act']) {
 	$act = $_REQUEST['act'];
diff --git a/src/usr/local/www/system_certmanager.php b/src/usr/local/www/system_certmanager.php
index 09f338942e..e668e541ea 100644
--- a/src/usr/local/www/system_certmanager.php
+++ b/src/usr/local/www/system_certmanager.php
@@ -52,9 +52,7 @@ if (isset($_REQUEST['userid']) && is_numericint($_REQUEST['userid'])) {
 
 if (isset($userid)) {
 	$cert_methods["existing"] = gettext("Choose an existing certificate");
-	if (!is_array($config['system']['user'])) {
-		$config['system']['user'] = array();
-	}
+	init_config_arr(array('system', 'user'));
 	$a_user =& $config['system']['user'];
 }
 
@@ -62,17 +60,11 @@ if (isset($_REQUEST['id']) && is_numericint($_REQUEST['id'])) {
 	$id = $_REQUEST['id'];
 }
 
-if (!is_array($config['ca'])) {
-	$config['ca'] = array();
-}
-
-$a_ca =& $config['ca'];
-
-if (!is_array($config['cert'])) {
-	$config['cert'] = array();
-}
+init_config_arr(array('ca'));
+$a_ca = &$config['ca'];
 
-$a_cert =& $config['cert'];
+init_config_arr(array('cert'));
+$a_cert = &$config['cert'];
 
 $internal_ca_count = 0;
 foreach ($a_ca as $ca) {
diff --git a/src/usr/local/www/system_crlmanager.php b/src/usr/local/www/system_crlmanager.php
index 57c3e33a49..af07e30602 100644
--- a/src/usr/local/www/system_crlmanager.php
+++ b/src/usr/local/www/system_crlmanager.php
@@ -48,23 +48,14 @@ if (isset($_REQUEST['id']) && ctype_alnum($_REQUEST['id'])) {
 	$id = $_REQUEST['id'];
 }
 
-if (!is_array($config['ca'])) {
-	$config['ca'] = array();
-}
-
-$a_ca =& $config['ca'];
-
-if (!is_array($config['cert'])) {
-	$config['cert'] = array();
-}
-
-$a_cert =& $config['cert'];
+init_config_arr(array('ca'));
+$a_ca = &$config['ca'];
 
-if (!is_array($config['crl'])) {
-	$config['crl'] = array();
-}
+init_config_arr(array('cert'));
+$a_cert = &$config['cert'];
 
-$a_crl =& $config['crl'];
+init_config_arr(array('crl'));
+$a_crl = &$config['crl'];
 
 foreach ($a_crl as $cid => $acrl) {
 	if (!isset($acrl['refid'])) {
diff --git a/src/usr/local/www/system_gateway_groups.php b/src/usr/local/www/system_gateway_groups.php
index 6f0f77b66e..8e6226de7f 100644
--- a/src/usr/local/www/system_gateway_groups.php
+++ b/src/usr/local/www/system_gateway_groups.php
@@ -33,15 +33,10 @@ require_once("filter.inc");
 require_once("shaper.inc");
 require_once("openvpn.inc");
 
-if (!is_array($config['gateways'])) {
-	$config['gateways'] = array();
-}
-
-if (!is_array($config['gateways']['gateway_group'])) {
-	$config['gateways']['gateway_group'] = array();
-}
-
+init_config_arr(array('gateways', 'gateway_group'));
 $a_gateway_groups = &$config['gateways']['gateway_group'];
+
+init_config_arr(array('gateways', 'gateway_item'));
 $a_gateways = &$config['gateways']['gateway_item'];
 $changedesc = gettext("Gateway Groups") . ": ";
 
diff --git a/src/usr/local/www/system_gateway_groups_edit.php b/src/usr/local/www/system_gateway_groups_edit.php
index 903e3579bf..0028d2dcd2 100644
--- a/src/usr/local/www/system_gateway_groups_edit.php
+++ b/src/usr/local/www/system_gateway_groups_edit.php
@@ -31,13 +31,7 @@ require_once("guiconfig.inc");
 require_once("ipsec.inc");
 require_once("vpn.inc");
 
-if (!is_array($config['gateways'])) {
-	$config['gateways'] = array();
-}
-if (!is_array($config['gateways']['gateway_group'])) {
-	$config['gateways']['gateway_group'] = array();
-}
-
+init_config_arr(array('gateways', 'gateway_group'));
 $a_gateway_groups = &$config['gateways']['gateway_group'];
 $a_gateways = return_gateways_array();
 
diff --git a/src/usr/local/www/system_gateways.php b/src/usr/local/www/system_gateways.php
index f063054ba2..4d7b342cf1 100644
--- a/src/usr/local/www/system_gateways.php
+++ b/src/usr/local/www/system_gateways.php
@@ -35,14 +35,7 @@ require_once("gwlb.inc");
 
 $simplefields = array('defaultgw4', 'defaultgw6');
 
-if (!is_array($config['gateways'])) {
-	$config['gateways'] = array();
-}
-
-if (!is_array($config['gateways']['gateway_item'])) {
-	$config['gateways']['gateway_item'] = array();
-}
-
+init_config_arr(array('gateways', 'gateway_item'));
 $a_gateway_item = &$config['gateways']['gateway_item'];
 
 $pconfig = $_REQUEST;
diff --git a/src/usr/local/www/system_gateways_edit.php b/src/usr/local/www/system_gateways_edit.php
index 280e4bc123..ab3da238cc 100644
--- a/src/usr/local/www/system_gateways_edit.php
+++ b/src/usr/local/www/system_gateways_edit.php
@@ -37,14 +37,7 @@ if (isset($_POST['referer'])) {
 
 $a_gateways = return_gateways_array(true, false, true, true);
 
-if (!is_array($config['gateways'])) {
-	$config['gateways'] = array();
-}
-
-if (!is_array($config['gateways']['gateway_item'])) {
-	$config['gateways']['gateway_item'] = array();
-}
-
+init_config_arr(array('gateways', 'gateway_item'));
 $a_gateway_item = &$config['gateways']['gateway_item'];
 $dpinger_default = return_dpinger_defaults();
 
diff --git a/src/usr/local/www/system_groupmanager.php b/src/usr/local/www/system_groupmanager.php
index e18e92a4a6..1eac340334 100644
--- a/src/usr/local/www/system_groupmanager.php
+++ b/src/usr/local/www/system_groupmanager.php
@@ -39,10 +39,7 @@ require_once("pfsense-utils.inc");
 $logging_level = LOG_WARNING;
 $logging_prefix = gettext("Local User Database");
 
-if (!is_array($config['system']['group'])) {
-	$config['system']['group'] = array();
-}
-
+init_config_arr(array('system', 'group'));
 $a_group = &$config['system']['group'];
 
 unset($id);
@@ -239,6 +236,7 @@ if (isset($_POST['save'])) {
 		 * changed.
 		 */
 		if (is_array($group['member'])) {
+			init_config_arr(array('system', 'user'));
 			$a_user = &$config['system']['user'];
 			foreach ($a_user as & $user) {
 				if (in_array($user['uid'], $group['member'])) {
diff --git a/src/usr/local/www/system_groupmanager_addprivs.php b/src/usr/local/www/system_groupmanager_addprivs.php
index eb2f8685da..126522c5dd 100644
--- a/src/usr/local/www/system_groupmanager_addprivs.php
+++ b/src/usr/local/www/system_groupmanager_addprivs.php
@@ -43,7 +43,8 @@ $groupid = $_REQUEST['groupid'];
 $pgtitle = array(gettext("System"), gettext("User Manager"), gettext("Groups"), gettext("Edit"), gettext("Add Privileges"));
 $pglinks = array("", "system_usermanager.php", "system_groupmanager.php", "system_groupmanager.php?act=edit&groupid=" . $groupid, "@self");
 
-$a_group = & $config['system']['group'][$groupid];
+init_config_arr(array('system', 'group', $groupid));
+$a_group = &$config['system']['group'][$groupid];
 
 if (!is_array($a_group)) {
 	pfSenseHeader("system_groupmanager.php?id={$groupid}");
diff --git a/src/usr/local/www/system_hasync.php b/src/usr/local/www/system_hasync.php
index 6ac242bb59..8d8e4bb53a 100644
--- a/src/usr/local/www/system_hasync.php
+++ b/src/usr/local/www/system_hasync.php
@@ -28,10 +28,7 @@
 
 require_once("guiconfig.inc");
 
-if (!is_array($config['hasync'])) {
-	$config['hasync'] = array();
-}
-
+init_config_arr(array('hasync'));
 $a_hasync = &$config['hasync'];
 
 $checkbox_names = array(
diff --git a/src/usr/local/www/system_routes.php b/src/usr/local/www/system_routes.php
index c32c1b3f5c..e5d760c280 100644
--- a/src/usr/local/www/system_routes.php
+++ b/src/usr/local/www/system_routes.php
@@ -35,14 +35,7 @@ require_once("functions.inc");
 require_once("filter.inc");
 require_once("shaper.inc");
 
-if (!is_array($config['staticroutes'])) {
-	$config['staticroutes'] = array();
-}
-
-if (!is_array($config['staticroutes']['route'])) {
-	$config['staticroutes']['route'] = array();
-}
-
+init_config_arr(array('staticroutes', 'route'));
 $a_routes = &$config['staticroutes']['route'];
 $a_gateways = return_gateways_array(true, true, true);
 $changedesc_prefix = gettext("Static Routes") . ": ";
diff --git a/src/usr/local/www/system_routes_edit.php b/src/usr/local/www/system_routes_edit.php
index 167aa861aa..c762b7a81d 100644
--- a/src/usr/local/www/system_routes_edit.php
+++ b/src/usr/local/www/system_routes_edit.php
@@ -37,14 +37,7 @@ require_once("gwlb.inc");
 
 $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_routes.php');
 
-if (!is_array($config['staticroutes'])) {
-	$config['staticroutes'] = array();
-}
-
-if (!is_array($config['staticroutes']['route'])) {
-	$config['staticroutes']['route'] = array();
-}
-
+init_config_arr(array('staticroutes', 'route'));
 $a_routes = &$config['staticroutes']['route'];
 $a_gateways = return_gateways_array(true, true);
 
diff --git a/src/usr/local/www/system_user_settings.php b/src/usr/local/www/system_user_settings.php
index bab3746081..cd9faefcd1 100644
--- a/src/usr/local/www/system_user_settings.php
+++ b/src/usr/local/www/system_user_settings.php
@@ -31,6 +31,7 @@
 
 $pgtitle = array(gettext("System"), gettext("User Settings"));
 
+init_config_arr(array('system', 'user'));
 $a_user = &$config['system']['user'];
 
 if (isset($_SESSION['Username']) && isset($userindex[$_SESSION['Username']])) {
diff --git a/src/usr/local/www/system_usermanager.php b/src/usr/local/www/system_usermanager.php
index 2b7bdd928b..cd7b50c280 100644
--- a/src/usr/local/www/system_usermanager.php
+++ b/src/usr/local/www/system_usermanager.php
@@ -45,10 +45,7 @@ if (isset($_REQUEST['userid']) && is_numericint($_REQUEST['userid'])) {
 	$id = $_REQUEST['userid'];
 }
 
-if (!isset($config['system']['user']) || !is_array($config['system']['user'])) {
-	$config['system']['user'] = array();
-}
-
+init_config_arr(array('system', 'user'));
 $a_user = &$config['system']['user'];
 $act = $_REQUEST['act'];
 
diff --git a/src/usr/local/www/system_usermanager_passwordmg.php b/src/usr/local/www/system_usermanager_passwordmg.php
index 27686f93dc..ab0ddb615c 100644
--- a/src/usr/local/www/system_usermanager_passwordmg.php
+++ b/src/usr/local/www/system_usermanager_passwordmg.php
@@ -46,11 +46,14 @@ if (isset($_POST['save'])) {
 	if ($_POST['passwordfld1'] != $_POST['passwordfld2']) {
 		$input_errors[] = gettext("The passwords do not match.");
 	}
+	if (!isset($config['system']['user'][$userindex[$_SESSION['Username']]]) ||
+	    !is_array($config['system']['user'][$userindex[$_SESSION['Username']]])) {
+		$input_errors[] = gettext("Could not locate this user.");
+	}
 
 	if (!$input_errors) {
 		phpsession_begin();
 		// all values are okay --> saving changes
-
 		$userent =& $config['system']['user'][$userindex[$_SESSION['Username']]];
 		local_user_set_password($userent, $_POST['passwordfld1']);
 		local_user_set($userent);
diff --git a/src/usr/local/www/vpn_ipsec.php b/src/usr/local/www/vpn_ipsec.php
index fa2d74afea..d3db49e91e 100644
--- a/src/usr/local/www/vpn_ipsec.php
+++ b/src/usr/local/www/vpn_ipsec.php
@@ -37,18 +37,8 @@ require_once("shaper.inc");
 require_once("ipsec.inc");
 require_once("vpn.inc");
 
-if(!is_array($config['ipsec'])){
-	$config['ipsec'] = array();
-}
-
-if (!is_array($config['ipsec']['phase1'])) {
-	$config['ipsec']['phase1'] = array();
-}
-
-if (!is_array($config['ipsec']['phase2'])) {
-	$config['ipsec']['phase2'] = array();
-}
-
+init_config_arr(array('ipsec', 'phase1'));
+init_config_arr(array('ipsec', 'phase2'));
 $a_phase1 = &$config['ipsec']['phase1'];
 $a_phase2 = &$config['ipsec']['phase2'];
 
diff --git a/src/usr/local/www/vpn_ipsec_keys.php b/src/usr/local/www/vpn_ipsec_keys.php
index b8750dce47..4a139d55f6 100644
--- a/src/usr/local/www/vpn_ipsec_keys.php
+++ b/src/usr/local/www/vpn_ipsec_keys.php
@@ -36,17 +36,12 @@ require_once("ipsec.inc");
 require_once("vpn.inc");
 require_once("filter.inc");
 
-if (!is_array($config['ipsec'])) {
-	$config['ipsec'] = array();
-}
-
-if (!is_array($config['ipsec']['mobilekey'])) {
-	$config['ipsec']['mobilekey'] = array();
-}
+init_config_arr(array('ipsec', 'mobilekey'));
 ipsec_mobilekey_sort();
 $a_secret = &$config['ipsec']['mobilekey'];
 
 $userkeys = array();
+init_config_arr(array('system', 'user'));
 foreach ($config['system']['user'] as $id => $user) {
 	if (!empty($user['ipsecpsk'])) {
 		$userkeys[] = array('ident' => $user['name'], 'type' => 'PSK', 'pre-shared-key' => $user['ipsecpsk'], 'id' => $id);;
diff --git a/src/usr/local/www/vpn_ipsec_keys_edit.php b/src/usr/local/www/vpn_ipsec_keys_edit.php
index e4f1ea81c7..71850299df 100644
--- a/src/usr/local/www/vpn_ipsec_keys_edit.php
+++ b/src/usr/local/www/vpn_ipsec_keys_edit.php
@@ -35,14 +35,7 @@ require_once("guiconfig.inc");
 require_once("ipsec.inc");
 require_once("vpn.inc");
 
-if (!is_array($config['ipsec'])) {
-	$config['ipsec'] = array();
-}
-
-if (!is_array($config['ipsec']['mobilekey'])) {
-	$config['ipsec']['mobilekey'] = array();
-}
-
+init_config_arr(array('ipsec', 'mobilekey'));
 ipsec_mobilekey_sort();
 $a_secret = &$config['ipsec']['mobilekey'];
 
diff --git a/src/usr/local/www/vpn_ipsec_mobile.php b/src/usr/local/www/vpn_ipsec_mobile.php
index 4f2beb08b6..02ac35e455 100644
--- a/src/usr/local/www/vpn_ipsec_mobile.php
+++ b/src/usr/local/www/vpn_ipsec_mobile.php
@@ -37,20 +37,10 @@ require_once("ipsec.inc");
 require_once("vpn.inc");
 require_once("filter.inc");
 
-if (!is_array($config['ipsec'])) {
-	$config['ipsec'] = array();
-}
-
-if (!is_array($config['ipsec']['phase1'])) {
-	$config['ipsec']['phase1'] = array();
-}
-
+init_config_arr(array('ipsec', 'phase1'));
 $a_phase1 = &$config['ipsec']['phase1'];
 
-if (!is_array($config['ipsec']['client'])) {
-	$config['ipsec']['client'] = array();
-}
-
+init_config_arr(array('ipsec', 'client'));
 $a_client = &$config['ipsec']['client'];
 
 if (count($a_client)) {
diff --git a/src/usr/local/www/vpn_ipsec_phase1.php b/src/usr/local/www/vpn_ipsec_phase1.php
index d8677249f0..704c3c4e75 100644
--- a/src/usr/local/www/vpn_ipsec_phase1.php
+++ b/src/usr/local/www/vpn_ipsec_phase1.php
@@ -45,18 +45,8 @@ if ($_REQUEST['generatekey']) {
 	exit;
 }
 
-if (!is_array($config['ipsec'])) {
-	$config['ipsec'] = array();
-}
-
-if (!is_array($config['ipsec']['phase1'])) {
-	$config['ipsec']['phase1'] = array();
-}
-
-if (!is_array($config['ipsec']['phase2'])) {
-	$config['ipsec']['phase2'] = array();
-}
-
+init_config_arr(array('ipsec', 'phase1'));
+init_config_arr(array('ipsec', 'phase2'));
 $a_phase1 = &$config['ipsec']['phase1'];
 $a_phase2 = &$config['ipsec']['phase2'];
 
diff --git a/src/usr/local/www/vpn_ipsec_phase2.php b/src/usr/local/www/vpn_ipsec_phase2.php
index 02ffafb412..0229617ef4 100644
--- a/src/usr/local/www/vpn_ipsec_phase2.php
+++ b/src/usr/local/www/vpn_ipsec_phase2.php
@@ -36,20 +36,10 @@ require_once("guiconfig.inc");
 require_once("ipsec.inc");
 require_once("vpn.inc");
 
-if (!is_array($config['ipsec']['client'])) {
-	$config['ipsec']['client'] = array();
-}
-
+init_config_arr(array('ipsec', 'client'));
 $a_client = &$config['ipsec']['client'];
-
-if (!is_array($config['ipsec']['phase1'])) {
-	$config['ipsec']['phase1'] = array();
-}
-
-if (!is_array($config['ipsec']['phase2'])) {
-	$config['ipsec']['phase2'] = array();
-}
-
+init_config_arr(array('ipsec', 'phase1'));
+init_config_arr(array('ipsec', 'phase2'));
 $a_phase1 = &$config['ipsec']['phase1'];
 $a_phase2 = &$config['ipsec']['phase2'];
 
diff --git a/src/usr/local/www/vpn_l2tp.php b/src/usr/local/www/vpn_l2tp.php
index 4e666f8f44..10a906890f 100644
--- a/src/usr/local/www/vpn_l2tp.php
+++ b/src/usr/local/www/vpn_l2tp.php
@@ -29,9 +29,7 @@
 require_once("guiconfig.inc");
 require_once("vpn.inc");
 
-if (!is_array($config['l2tp']['radius'])) {
-	$config['l2tp']['radius'] = array();
-}
+init_config_arr(array('l2tp', 'radius'));
 $l2tpcfg = &$config['l2tp'];
 
 $pconfig['remoteip'] = $l2tpcfg['remoteip'];
diff --git a/src/usr/local/www/vpn_l2tp_users.php b/src/usr/local/www/vpn_l2tp_users.php
index 110e01a50e..b61e71c77a 100644
--- a/src/usr/local/www/vpn_l2tp_users.php
+++ b/src/usr/local/www/vpn_l2tp_users.php
@@ -34,9 +34,7 @@ require_once("guiconfig.inc");
 require_once("pfsense-utils.inc");
 require_once("vpn.inc");
 
-if (!is_array($config['l2tp']['user'])) {
-	$config['l2tp']['user'] = array();
-}
+init_config_arr(array('l2tp', 'user'));
 $a_secret = &$config['l2tp']['user'];
 
 
diff --git a/src/usr/local/www/vpn_l2tp_users_edit.php b/src/usr/local/www/vpn_l2tp_users_edit.php
index 0483ae7baf..0fe2f9ad68 100644
--- a/src/usr/local/www/vpn_l2tp_users_edit.php
+++ b/src/usr/local/www/vpn_l2tp_users_edit.php
@@ -48,10 +48,7 @@ require_once("guiconfig.inc");
 require_once("pfsense-utils.inc");
 require_once("vpn.inc");
 
-if (!is_array($config['l2tp']['user'])) {
-	$config['l2tp']['user'] = array();
-}
-
+init_config_arr(array('l2tp', 'user'));
 $a_secret = &$config['l2tp']['user'];
 
 if (isset($_REQUEST['id']) && is_numericint($_REQUEST['id'])) {
diff --git a/src/usr/local/www/vpn_openvpn_client.php b/src/usr/local/www/vpn_openvpn_client.php
index 56eedb03c1..e1c838a6f7 100644
--- a/src/usr/local/www/vpn_openvpn_client.php
+++ b/src/usr/local/www/vpn_openvpn_client.php
@@ -34,33 +34,17 @@ require_once("pkg-utils.inc");
 
 global $openvpn_topologies, $openvpn_tls_modes;
 
-if (!is_array($config['openvpn'])) {
-	$config['openvpn'] = array();
-}
-
-if (!is_array($config['openvpn']['openvpn-client'])) {
-	$config['openvpn']['openvpn-client'] = array();
-}
-
+init_config_arr(array('openvpn', 'openvpn-client'));
 $a_client = &$config['openvpn']['openvpn-client'];
 
-if (!is_array($config['ca'])) {
-	$config['ca'] = array();
-}
-
-$a_ca =& $config['ca'];
-
-if (!is_array($config['cert'])) {
-	$config['cert'] = array();
-}
+init_config_arr(array('ca'));
+$a_ca = &$config['ca'];
 
-$a_cert =& $config['cert'];
-
-if (!is_array($config['crl'])) {
-	$config['crl'] = array();
-}
+init_config_arr(array('cert'));
+$a_cert = &$config['cert'];
 
-$a_crl =& $config['crl'];
+init_config_arr(array('crl'));
+$a_crl = &$config['crl'];
 
 if (isset($_REQUEST['id']) && is_numericint($_REQUEST['id'])) {
 	$id = $_REQUEST['id'];
diff --git a/src/usr/local/www/vpn_openvpn_csc.php b/src/usr/local/www/vpn_openvpn_csc.php
index b0911d2895..5d06a0e4a2 100644
--- a/src/usr/local/www/vpn_openvpn_csc.php
+++ b/src/usr/local/www/vpn_openvpn_csc.php
@@ -34,14 +34,7 @@ require_once("pkg-utils.inc");
 
 global $openvpn_tls_server_modes;
 
-if (!is_array($config['openvpn'])) {
-	$config['openvpn'] = array();
-}
-
-if (!is_array($config['openvpn']['openvpn-csc'])) {
-	$config['openvpn']['openvpn-csc'] = array();
-}
-
+init_config_arr(array('openvpn', 'openvpn-csc'));
 $a_csc = &$config['openvpn']['openvpn-csc'];
 
 if (isset($_REQUEST['id']) && is_numericint($_REQUEST['id'])) {
diff --git a/src/usr/local/www/vpn_openvpn_server.php b/src/usr/local/www/vpn_openvpn_server.php
index 5912cb7c81..10b4c51a7f 100644
--- a/src/usr/local/www/vpn_openvpn_server.php
+++ b/src/usr/local/www/vpn_openvpn_server.php
@@ -34,33 +34,17 @@ require_once("pkg-utils.inc");
 
 global $openvpn_topologies, $openvpn_tls_modes;
 
-if (!is_array($config['openvpn'])) {
-	$config['openvpn'] = array();
-}
-
-if (!is_array($config['openvpn']['openvpn-server'])) {
-	$config['openvpn']['openvpn-server'] = array();
-}
-
+init_config_arr(array('openvpn', 'openvpn-server'));
 $a_server = &$config['openvpn']['openvpn-server'];
 
-if (!is_array($config['ca'])) {
-	$config['ca'] = array();
-}
-
-$a_ca =& $config['ca'];
-
-if (!is_array($config['cert'])) {
-	$config['cert'] = array();
-}
+init_config_arr(array('ca'));
+$a_ca = &$config['ca'];
 
-$a_cert =& $config['cert'];
-
-if (!is_array($config['crl'])) {
-	$config['crl'] = array();
-}
+init_config_arr(array('cert'));
+$a_cert = &$config['cert'];
 
-$a_crl =& $config['crl'];
+init_config_arr(array('crl'));
+$a_crl = &$config['crl'];
 
 foreach ($a_crl as $cid => $acrl) {
 	if (!isset($acrl['refid'])) {
diff --git a/src/usr/local/www/widgets/widgets/captive_portal_status.widget.php b/src/usr/local/www/widgets/widgets/captive_portal_status.widget.php
index 842c5dafae..c49c16b073 100644
--- a/src/usr/local/www/widgets/widgets/captive_portal_status.widget.php
+++ b/src/usr/local/www/widgets/widgets/captive_portal_status.widget.php
@@ -30,10 +30,8 @@ require_once("pfsense-utils.inc");
 require_once("functions.inc");
 require_once("captiveportal.inc");
 
-if (!is_array($config['captiveportal'])) {
-	$config['captiveportal'] = array();
-}
-$a_cp =& $config['captiveportal'];
+init_config_arr(array('captiveportal'));
+$a_cp = &$config['captiveportal'];
 
 $cpzone = $_GET['zone'];
 if (isset($_POST['zone'])) {
diff --git a/src/usr/local/www/widgets/widgets/load_balancer_status.widget.php b/src/usr/local/www/widgets/widgets/load_balancer_status.widget.php
index bb8f7f68a6..0ee64b5586 100644
--- a/src/usr/local/www/widgets/widgets/load_balancer_status.widget.php
+++ b/src/usr/local/www/widgets/widgets/load_balancer_status.widget.php
@@ -33,13 +33,9 @@ require_once("vslb.inc");
 $now = time();
 $year = date("Y");
 
-if (!is_array($config['load_balancer']['lbpool'])) {
-	$config['load_balancer']['lbpool'] = array();
-}
-if (!is_array($config['load_balancer']['virtual_server'])) {
-	$config['load_balancer']['virtual_server'] = array();
-}
+init_config_arr(array('load_balancer', 'virtual_server'));
 $a_vs = &$config['load_balancer']['virtual_server'];
+init_config_arr(array('load_balancer', 'lbpool'));
 $a_pool = &$config['load_balancer']['lbpool'];
 $rdr_a = get_lb_redirects();
 $relay_hosts = get_lb_summary();
diff --git a/src/usr/local/www/wizards/openvpn_wizard.inc b/src/usr/local/www/wizards/openvpn_wizard.inc
index b8a4181c13..0219691673 100644
--- a/src/usr/local/www/wizards/openvpn_wizard.inc
+++ b/src/usr/local/www/wizards/openvpn_wizard.inc
@@ -65,7 +65,7 @@ function step1_submitphpaction() {
 function step2_stepbeforeformdisplay() {
 	global $pkg, $stepid;
 
-	$fields =& $pkg['step'][1]['fields']['field'];
+	$fields = &$pkg['step'][1]['fields']['field'];
 
 	$found = false;
 	$authlist = auth_get_authserver_list();
@@ -127,7 +127,7 @@ function step3_submitphpaction() {
 function step4_stepbeforeformdisplay() {
 	global $pkg, $stepid;
 
-	$fields =& $pkg['step'][3]['fields']['field'];
+	$fields = &$pkg['step'][3]['fields']['field'];
 
 	$found = false;
 	$authlist = auth_get_authserver_list();
@@ -277,7 +277,7 @@ function step9_stepbeforeformdisplay() {
 		$city = $cavl['L'];
 		$org = $cavl['O'];
 	}
-	$fields =& $pkg['step'][$stepid]['fields']['field'];
+	$fields = &$pkg['step'][$stepid]['fields']['field'];
 
 	foreach ($fields as $idx => $field) {
 		switch ($field['name']) {
diff --git a/src/usr/local/www/wizards/traffic_shaper_wizard_dedicated.inc b/src/usr/local/www/wizards/traffic_shaper_wizard_dedicated.inc
index 9938a6c153..c89f0dd4f3 100644
--- a/src/usr/local/www/wizards/traffic_shaper_wizard_dedicated.inc
+++ b/src/usr/local/www/wizards/traffic_shaper_wizard_dedicated.inc
@@ -26,7 +26,7 @@ require_once("util.inc");
 function step1_stepbeforeformdisplay() {
 	global $stepid, $savemsg, $pkg;
 
-	$fields =& $pkg['step'][0]['fields']['field'];
+	$fields = &$pkg['step'][0]['fields']['field'];
 
 	$wans = 0;
 	$lans = 0;
@@ -91,7 +91,7 @@ function step2_stepbeforeformdisplay() {
 
 	$cfgname = "traffic_shaper_wizard_dedicated.xml";
 
-	$fields =& $pkg['step'][1]['fields']['field'];
+	$fields = &$pkg['step'][1]['fields']['field'];
 
 	/*
 	unset($config['ezshaper']['step2']);
@@ -338,9 +338,8 @@ function step3_stepbeforeformdisplay() {
 
 	$numberofconnections = intval($config['ezshaper']['step1']['numberofconnections']);
 
-	$fields =& $pkg['step'][1]['fields']['field'];
-
-	$voipfields =& $pkg['step'][2]['fields']['field'];
+	$fields = &$pkg['step'][1]['fields']['field'];
+	$voipfields = &$pkg['step'][2]['fields']['field'];
 
 	$voipfields = array();
 	$enablefields = array();
diff --git a/src/usr/local/www/wizards/traffic_shaper_wizard_multi_all.inc b/src/usr/local/www/wizards/traffic_shaper_wizard_multi_all.inc
index 6caacfaf75..101302dcae 100644
--- a/src/usr/local/www/wizards/traffic_shaper_wizard_multi_all.inc
+++ b/src/usr/local/www/wizards/traffic_shaper_wizard_multi_all.inc
@@ -26,7 +26,7 @@ require_once("util.inc");
 function step1_stepbeforeformdisplay() {
 	global $stepid, $savemsg, $pkg;
 
-	$fields =& $pkg['step'][0]['fields']['field'];
+	$fields = &$pkg['step'][0]['fields']['field'];
 
 	$lans = 0;
 	$wans = 0;
@@ -119,7 +119,7 @@ function step2_stepbeforeformdisplay() {
 	}
 	$cfgname = "traffic_shaper_wizard_multi_all.xml";
 
-	$fields =& $pkg['step'][1]['fields']['field'];
+	$fields = &$pkg['step'][1]['fields']['field'];
 
 	/*
 	unset($config['ezshaper']['step2']);
@@ -387,9 +387,8 @@ function step3_stepbeforeformdisplay() {
 	$numberofconnections = intval($config['ezshaper']['step1']['numberofconnections']);
 	$numberoflocalinterfaces = intval($config['ezshaper']['step1']['numberoflocalinterfaces']);
 
-	$fields =& $pkg['step'][1]['fields']['field'];
-
-	$voipfields =& $pkg['step'][2]['fields']['field'];
+	$fields = &$pkg['step'][1]['fields']['field'];
+	$voipfields = &$pkg['step'][2]['fields']['field'];
 
 	$voipfields = array();
 	$enablefields = array();
diff --git a/src/usr/local/www/xmlrpc.php b/src/usr/local/www/xmlrpc.php
index e5b005b486..8896b420d5 100644
--- a/src/usr/local/www/xmlrpc.php
+++ b/src/usr/local/www/xmlrpc.php
@@ -449,6 +449,7 @@ class pfsense_xmlrpc_server {
 					continue;
 				}
 				$l_roll_idx = $l_rolls[$zone][$roll['number']];
+				init_config_arr(array('voucher', $zone));
 				$l_vouchers = &$config['voucher'][$zone];
 				$l_roll = $l_vouchers['roll'][$l_roll_idx];
 				if (!isset($l_roll['lastsync'])) {
