diff --git a/interface/web/vm/openvz_vm_del.php b/interface/web/vm/openvz_vm_del.php
index c8d8e196af6032dd1150643fba8a07d5e2c36a55..8d288444b6c6436ac05ab2e73b8d8c8923d4f447 100644
--- a/interface/web/vm/openvz_vm_del.php
+++ b/interface/web/vm/openvz_vm_del.php
@@ -49,6 +49,14 @@ $app->uses('tpl,tform');
 $app->load('tform_actions');
 
 class page_action extends tform_actions {
+
+	function onAfterDelete() {
+		global $app, $conf;
+		
+		//* Release all IP addresses which are assigned to this VM
+		$app->db->query("UPDATE openvz_ip SET vm_id = 0 WHERE vm_id = '".$this->id."'");
+		
+	}
 	
 }
 
diff --git a/interface/web/vm/openvz_vm_edit.php b/interface/web/vm/openvz_vm_edit.php
index 451bc01eec9728ed5a6803066f08bb90547800dc..bc0324907bf647c20049fa767f2297df4533cef2 100644
--- a/interface/web/vm/openvz_vm_edit.php
+++ b/interface/web/vm/openvz_vm_edit.php
@@ -183,14 +183,6 @@ class page_action extends tform_actions {
 		
 	}
 	
-	function onAfterDelete() {
-		global $app, $conf;
-		
-		//* Release all IP addresses which are assigned to this VM
-		$app->db->query("UPDATE openvz_ip SET vm_id = 0 WHERE vm_id = '".$this->id."'");
-		
-	}
-	
 	function applyTemplate() {
 		global $app, $conf;
 		
diff --git a/server/plugins-available/openvz_plugin.inc.php b/server/plugins-available/openvz_plugin.inc.php
index a9c630e5a5fb9dba749c500e1bb48838ca2cf660..a0907ff8653733eff285e343862caab0750ebe4b 100644
--- a/server/plugins-available/openvz_plugin.inc.php
+++ b/server/plugins-available/openvz_plugin.inc.php
@@ -77,7 +77,7 @@ class openvz_plugin {
 			return;
 		}
 		
-		$tmp = $app->db->queryOneRecord("SELECT template_file FROM openvz_ostemplate WHERE ostemplate_id = ".$vm['ostemplate_id']);
+		$tmp = $app->db->queryOneRecord("SELECT template_file FROM openvz_ostemplate WHERE ostemplate_id = ".$data['new']['ostemplate_id']);
 		$ostemplate = escapeshellcmd($tmp['template_file']);
 		unset($tmp);