Index: PitBull.lua
===================================================================
--- PitBull.lua	(revision 39459)
+++ PitBull.lua	(working copy)
@@ -1956,7 +1956,23 @@
 	end
 end
 
-local currentMovingFrame
+local startMovingFrame, stopMovingFrame
+do
+	local currentMovingFrame
+	startMovingFrame = function (frame)
+		if currentMovingFrame then
+			currentMovingFrame:StopMovingOrSizing()
+		end
+		currentMovingFrame = frame
+		currentMovingFrame:StartMoving()
+	end
+	
+	stopMovingFrame = function ()
+		if currentMovingFrame then
+			currentMovingFrame:StopMovingOrSizing()
+			currentMovingFrame = nil
+		end
+	end
 
 function PitBull:PARTY_MEMBERS_CHANGED() -- also PARTY_LEADER_CHANGED, RAID_ROSTER_UPDATE, and UNIT_PET
 	NumRaidMembers = GetNumRaidMembers()
@@ -1980,13 +1996,11 @@
 		end
 	end
 	
-	if currentMovingFrame then
-		currentMovingFrame:StopMovingOrSizing()
-		currentMovingFrame = nil
-	end
+	stopMovingFrame()
 	
 	framesByUnit_needsUpdate = true
 	
+	local groups = self.db.profile.groups
 	local showparty, showraid = ShouldShowParty(), ShouldShowRaid()
 	if not showparty then
 		for cluster in pairs(clusters) do
@@ -2003,14 +2017,14 @@
 		end
 	end
 	if showparty then
-		for group, db in pairs(self.db.profile.groups) do
+		for group, db in pairs(groups) do
 			if not db.hidden and group:find("^party") then
 				ScheduleCreateCluster(group)
 			end
 		end
 	end
 	if showraid then
-		for group, db in pairs(self.db.profile.groups) do
+		for group, db in pairs(groups) do
 			if not db.hidden then
 				if group:find("^raid") or group:find("^maintank") or group:find("^mainassist") then
 					ScheduleCreateCluster(group)
@@ -2023,7 +2037,7 @@
 	
 	for frame in pairs(allFrames) do
 		local unit = frame:GetUnit()
-		if not unit or self.db.profile.groups[frame.group].hidden then
+		if not unit or groups[frame.group].hidden then
 			self:ClearUnitFrame(frame)
 		elseif showparty and unit:find("^party") then
 			if configMode or UnitExists(unit) then
@@ -2045,9 +2059,10 @@
 	end
 	
 	framesByUnit_needsUpdate = true
-	
+
+	local petframe_visible = (configMode or UnitExists('pet')) and not groups['pet'].hidden
 	for frame in self:IterateUnitFramesForUnit("pet") do
-		if not self.db.profile.groups['pet'].hidden and (configMode or UnitExists('pet')) then
+		if petframe_visible then
 			if frame:IsShown() then
 				self:PopulateUnitFrame(frame)
 			end
@@ -2064,8 +2079,9 @@
 end
 
 function PitBull:PLAYER_PET_CHANGED()
+	local petframe_visible = (configMode or UnitExists('pet')) and not self.db.profile.groups['pet'].hidden
 	for frame in self:IterateUnitFramesForUnit("pet") do
-		if not self.db.profile.groups['pet'].hidden and (configMode or UnitExists('pet')) then
+		if petframe_visible then
 			if frame:IsShown() then
 				self:PopulateUnitFrame(frame, true)
 			end
@@ -2101,9 +2117,10 @@
 
 function PitBull:UpdateAll()
 	lazyLayout = lazyLayout + 1
+	local groups = self.db.profile.groups
 	for frame in pairs(frames) do
 		local unit = frame:GetUnit()
-		if (configMode or UnitExists(unit)) and ShouldShowUnit(unit) and not self.db.profile.groups[frame.group].hidden then
+		if (configMode or UnitExists(unit)) and ShouldShowUnit(unit) and not groups[frame.group].hidden then
 			self:UpdateLayout(frame)
 			self:UpdateFrame(frame)
 		end
@@ -2533,10 +2550,8 @@
 end
 
 function PitBull:_ClearUnitFrame(frame)
-	if currentMovingFrame then
-		currentMovingFrame:StopMovingOrSizing()
-		currentMovingFrame = nil
-	end
+	stopMovingFrame()
+
 	if not frames[frame] then
 		return
 	end
@@ -2766,20 +2781,9 @@
 		return
 	end
 	
-	if currentMovingFrame then
-		currentMovingFrame:StopMovingOrSizing()
-		currentMovingFrame = nil
-	end
-	
 	-- also want to move group if grouped
 	local cluster = this.cluster
-	if cluster --[[ and not PitBull.db.profile.groups[this.group].freeform ]] then
-		currentMovingFrame = clusters[cluster]
-		clusters[cluster]:StartMoving()
-	else
-		currentMovingFrame = this
-		this:StartMoving()
-	end
+	startMovingFrame(cluster and clusters[cluster] or this)
 end
 
 local function frame_OnDragStop(this)
@@ -2798,10 +2802,7 @@
 		db = self.db.profile.units[unit]
 	end
 	
-	if currentMovingFrame then
-		currentMovingFrame:StopMovingOrSizing()
-		currentMovingFrame = nil
-	end
+	stopMovingFrame()
 	
 	local x, y = this:GetCenter()
 	local s = this:GetEffectiveScale()
@@ -3402,10 +3403,9 @@
 	end
 	groupCache[#groupCache+1] = header
 	header.label = delFrame(header.label)
-	if currentMovingFrame then
-		currentMovingFrame:StopMovingOrSizing()
-		currentMovingFrame = nil
-	end
+	
+	stopMovingFrame()
+
 	header:Hide()
 	header:SetAttribute("template", nil)
 	header:SetAttribute("sortMethod", nil)
@@ -4609,10 +4609,7 @@
 		return
 	end
 	
-	if currentMovingFrame then
-		currentMovingFrame:StopMovingOrSizing()
-		currentMovingFrame = nil
-	end
+	stopMovingFrame()
 	
 	self.configMode = value
 	configMode = value
