diff --git a/resources/templates/provision/mitel/5324/MN_{$mac}.cfg b/resources/templates/provision/mitel/5324/MN_{$mac}.cfg
index d6a28f2e81..1d568b2548 100644
--- a/resources/templates/provision/mitel/5324/MN_{$mac}.cfg
+++ b/resources/templates/provision/mitel/5324/MN_{$mac}.cfg
@@ -268,7 +268,6 @@
0
{foreach $keys as $row}
-{if $row.device_key_type == "6"}
{if $row.device_key_line == "1"}{$feature = "6"}{$user_id = $user_id_1}{/if}
{if $row.device_key_line == "2"}{$feature = "7"}{$user_id = $user_id_2}{/if}
{if $row.device_key_line == "3"}{$feature = "8"}{$user_id = $user_id_3}{/if}
@@ -277,8 +276,9 @@
{if $row.device_key_line == "6"}{$feature = "11"}{$user_id = $user_id_6}{/if}
{if $row.device_key_line == "7"}{$feature = "12"}{$user_id = $user_id_7}{/if}
{if $row.device_key_line == "8"}{$feature = "13"}{$user_id = $user_id_8}{/if}
+{if $row.device_key_type == "6"}
-{/if}{if $row.device_key_type != "6"}
+{else}
{/if}
{/foreach}
diff --git a/resources/templates/provision/mitel/5330/MN_{$mac}.cfg b/resources/templates/provision/mitel/5330/MN_{$mac}.cfg
index 0c585c1d81..bd9647783d 100644
--- a/resources/templates/provision/mitel/5330/MN_{$mac}.cfg
+++ b/resources/templates/provision/mitel/5330/MN_{$mac}.cfg
@@ -268,7 +268,6 @@
0
{foreach $keys as $row}
-{if $row.device_key_type == "6"}
{if $row.device_key_line == "1"}{$feature = "6"}{$user_id = $user_id_1}{/if}
{if $row.device_key_line == "2"}{$feature = "7"}{$user_id = $user_id_2}{/if}
{if $row.device_key_line == "3"}{$feature = "8"}{$user_id = $user_id_3}{/if}
@@ -277,8 +276,9 @@
{if $row.device_key_line == "6"}{$feature = "11"}{$user_id = $user_id_6}{/if}
{if $row.device_key_line == "7"}{$feature = "12"}{$user_id = $user_id_7}{/if}
{if $row.device_key_line == "8"}{$feature = "13"}{$user_id = $user_id_8}{/if}
+{if $row.device_key_type == "6"}
-{/if}{if $row.device_key_type != "6"}
+{else}
{/if}
{/foreach}
diff --git a/resources/templates/provision/mitel/5340/MN_{$mac}.cfg b/resources/templates/provision/mitel/5340/MN_{$mac}.cfg
index 0c585c1d81..1d568b2548 100644
--- a/resources/templates/provision/mitel/5340/MN_{$mac}.cfg
+++ b/resources/templates/provision/mitel/5340/MN_{$mac}.cfg
@@ -1,4 +1,4 @@
-
+
1
{if isset($mitel_tftp_config)}{$mitel_tftp_config}{else}2
{/if}0
@@ -268,7 +268,6 @@
0
{foreach $keys as $row}
-{if $row.device_key_type == "6"}
{if $row.device_key_line == "1"}{$feature = "6"}{$user_id = $user_id_1}{/if}
{if $row.device_key_line == "2"}{$feature = "7"}{$user_id = $user_id_2}{/if}
{if $row.device_key_line == "3"}{$feature = "8"}{$user_id = $user_id_3}{/if}
@@ -277,8 +276,9 @@
{if $row.device_key_line == "6"}{$feature = "11"}{$user_id = $user_id_6}{/if}
{if $row.device_key_line == "7"}{$feature = "12"}{$user_id = $user_id_7}{/if}
{if $row.device_key_line == "8"}{$feature = "13"}{$user_id = $user_id_8}{/if}
+{if $row.device_key_type == "6"}
-{/if}{if $row.device_key_type != "6"}
+{else}
{/if}
{/foreach}