diff --git a/webgui/include/ajax/functions/AdminGroups.php b/webgui/include/ajax/functions/AdminGroups.php
index 73e43a165053371d0c7a1523b32dff050f85c497..2885737b981fdbfdc7975c3576f8e297684ace97 100644
--- a/webgui/include/ajax/functions/AdminGroups.php
+++ b/webgui/include/ajax/functions/AdminGroups.php
@@ -69,9 +69,29 @@ function getAdminGroup($params) {
 function removeAdminGroup($params) {
 	global $db;
 
-	$res = DBDo("DELETE FROM groups WHERE ID = ?",array($params[0]));
-	if (!is_numeric($res)) {
+	# Begin transaction
+	DBBegin();
+
+	# Unlink users from group
+	$res = DBDo("DELETE FROM users_to_groups WHERE GroupID = ?",array($params[0]));
+
+	# Delete group attribtues
+	if ($res !== FALSE) {
+		$res = DBDo("DELETE FROM group_attributes WHERE GroupID = ?",array($params[0]));
+	}
+
+	# Delete group
+	if ($res !== FALSE) {
+		$res = DBDo("DELETE FROM groups WHERE ID = ?",array($params[0]));
+	}
+
+	# Commit and return if successful
+	if ($res !== FALSE) {
+		DBCommit();
 		return $res;
+	# Else rollback database
+	} else {
+		DBRollback();
 	}
 
 	return NULL;
diff --git a/webgui/include/ajax/functions/AdminRealms.php b/webgui/include/ajax/functions/AdminRealms.php
index ab57ce71e0a4bc3864269b303d9d947c0c6afbcc..a457ca883d6b238cd3753e3abbd47736ff66c288 100644
--- a/webgui/include/ajax/functions/AdminRealms.php
+++ b/webgui/include/ajax/functions/AdminRealms.php
@@ -63,9 +63,23 @@ function getAdminRealm($params) {
 function removeAdminRealm($params) {
 	global $db;
 
-	$res = DBDo("DELETE FROM realms WHERE ID = ?",array($params[0]));
-	if (!is_numeric($res)) {
+	# Begin transaction
+	DBBegin();
+
+	# Delete user attribtues
+	$res = DBDo("DELETE FROM realm_attributes WHERE RealmID = ?",array($params[0]));
+
+	if ($res !== FALSE) {
+		$res = DBDo("DELETE FROM realms WHERE ID = ?",array($params[0]));
+	}
+
+	# Commit and return if successful
+	if ($res !== FALSE) {
+		DBCommit();
 		return $res;
+	# Else rollback database
+	} else {
+		DBRollback();
 	}
 
 	return NULL;
diff --git a/webgui/include/ajax/functions/AdminUsers.php b/webgui/include/ajax/functions/AdminUsers.php
index ce6bf56c0a0cbf95b22c00a1fd90d7187d4efdf6..43b3dc5187de796864a7ad6998cd9a5b03e31d42 100644
--- a/webgui/include/ajax/functions/AdminUsers.php
+++ b/webgui/include/ajax/functions/AdminUsers.php
@@ -63,9 +63,34 @@ function getAdminUser($params) {
 function removeAdminUser($params) {
 	global $db;
 
-	$res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0]));
-	if (!is_numeric($res)) {
+	# Begin transaction
+	DBBegin();
+
+	# Delete user information, if any
+	$res = DBDo("DELETE FROM wisp_userdata WHERE UserID = ?",array($params[0]));
+
+	# Delete user attribtues
+	if ($res !== FALSE) {
+		$res = DBDo("DELETE FROM user_attributes WHERE UserID = ?",array($params[0]));
+	}
+
+	# Remove user from groups
+	if ($res !== FALSE) {
+		$res = DBDo("DELETE FROM users_to_groups WHERE UserID = ?",array($params[0]));
+	}
+	
+	# Delete user
+	if ($res !== FALSE) {
+		$res = DBDo("DELETE FROM users WHERE ID = ?",array($params[0]));
+	}
+
+	# Commit and return if successful
+	if ($res !== FALSE) {
+		DBCommit();
 		return $res;
+	# Else rollback database
+	} else {
+		DBRollback();
 	}
 
 	return NULL;