function handlework(name,unit,i)
	local jobdata = jobs[unit.values[JOB]]
	
	if (name == "dispose") then
		local i = mmf.newObject(unit.target)
				
		if (unit.workstep == 0) then
			local yes = findpath_unititem(unit,i)
			
			if yes then
				unit.workstep = 1
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 1) then
			if (near(unit,i) == 1) then
				i.held = unit.fixed

				local structid = findfree("wc","struct")
				
				if (structid ~= 0) then
					local s = mmf.newObject(structid)
					
					local yes = findpath_unititem(unit,s)
					
					if yes then
						--s.reserved = true
						--s.target = unit.fixed
						unit.target2 = structid
						unit.workstep = 2
					else
						cancelwork(unit.fixed)
					end
				end
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 2) then
			local s = mmf.newObject(unit.target2)
			
			if (near(unit,s) == 1) then
				i.held = 0
				--s.target = 0
				delunit(unit.target)
				unit.target = 0
				unit.target2 = 0
				unit.reserved = false
				--s.reserved = false
				unit.workstep = 0
				unit.work = ""
			end
		end
	elseif (name == "metab") then
		if (unit.target2 == 0) then
			unit.target2 = unit.target
			
			unit.target = findfree("food","item")
		end
		
		if (unit.workstep == 0) and (unit.target ~= 0) then
			local i = mmf.newObject(unit.target)
			local yes = findpath_unititem(unit,i)
			
			if yes then
				unit.workstep = 1
				i.reserved = true
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 1) then
			local i = mmf.newObject(unit.target)
			if (near(unit,i) == 1) then
				i.held = unit.fixed

				local structid = unit.target2
				
				if (structid ~= 0) then
					local s = mmf.newObject(structid)
					
					local yes = findpath_unititem(unit,s)
					
					if yes then
						--s.reserved = true
						--s.target = unit.fixed
						unit.target2 = structid
						unit.workstep = 2
					else
						cancelwork(unit.fixed)
					end
				end
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 2) then
			local i = mmf.newObject(unit.target)
			local s = mmf.newObject(unit.target2)
			
			if (near(unit,s) == 1) then
				if (unit.wait < 50) then
					unit.wait = unit.wait + 1
				else
					unit.wait = 0
					i.held = 0
					i.reserved = true
					
					local jobdata = jobs[unit.values[JOB]]
					
					delunit(unit.target)
					local newid = MF_create("item")
					local new = mmf.newObject(newid)
					new.values[XPOS] = s.values[XPOS]
					new.values[YPOS] = s.values[YPOS]
					
					if (jobdata.name == "metab_cell") then
						new.strings[NAME] = "cellfood"
						new.strings[DESC] = "Food for the homunculi"
					else
						new.strings[NAME] = "sugar"
						new.strings[DESC] = "Sugar for patching wounds and producing energy"
					end
					additem(newid)
					
					unit.target = 0
					unit.target2 = 0
					unit.reserved = false
					s.reserved = false
					unit.workstep = 0
					unit.work = ""
				end
			end
		else
			cancelwork(unit.fixed)
		end
	elseif (name == "consume") then
		if (unit.target2 == 0) then
			unit.target2 = unit.target
			unit.target = findfree("sugar","item")
		end
		
		if (unit.workstep == 0) and (unit.target ~= 0) then
			local i = mmf.newObject(unit.target)
			local yes = findpath_unititem(unit,i)
			
			if yes then
				unit.workstep = 1
				i.reserved = true
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 1) then
			local i = mmf.newObject(unit.target)
			if (near(unit,i) == 1) then
				i.held = unit.fixed

				local structid = unit.target2
				
				if (structid ~= 0) then
					local s = mmf.newObject(structid)
					
					local yes = findpath_unititem(unit,s)
					
					if yes then
						--s.reserved = true
						--s.target = unit.fixed
						unit.target2 = structid
						unit.workstep = 2
					else
						cancelwork(unit.fixed)
					end
				end
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 2) then
			local i = mmf.newObject(unit.target)
			local s = mmf.newObject(unit.target2)
			
			if (near(unit,s) == 1) then
				if (unit.wait < 20) then
					unit.wait = unit.wait + 1
				else
					unit.wait = 0
					i.held = 0
					i.reserved = true
					
					local jobdata = jobs[unit.values[JOB]]
					
					delunit(unit.target)
					unit.target = 0
					unit.target2 = 0
					unit.reserved = false
					s.reserved = false
					unit.workstep = 0
					unit.work = ""
					
					energy = energy + 10.0
				end
			end
		else
			cancelwork(unit.fixed)
		end
	elseif (name == "heal") then
		if (unit.target2 == 0) then
			unit.target2 = unit.target
			
			unit.target = findfree("sugar","item")
		end
		
		if (unit.workstep == 0) and (unit.target ~= 0) then
			local i = mmf.newObject(unit.target)
			local yes = findpath_unititem(unit,i)
			
			if yes then
				unit.workstep = 1
				i.reserved = true
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 1) then
			local i = mmf.newObject(unit.target)
			if (near(unit,i) == 1) then
				i.held = unit.fixed

				local structid = unit.target2
				
				if (structid ~= 0) then
					local s = mmf.newObject(structid)
					
					local yes = findpath_unititem(unit,s)
					
					if yes then
						--s.reserved = true
						--s.target = unit.fixed
						unit.target2 = structid
						unit.workstep = 2
					else
						cancelwork(unit.fixed)
					end
				end
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 2) then
			local i = mmf.newObject(unit.target)
			local s = mmf.newObject(unit.target2)
			
			if (near(unit,s) == 1) then
				if (unit.wait < 20) then
					unit.wait = unit.wait + 1
				else
					unit.wait = 0
					i.held = 0
					i.reserved = true
					
					local jobdata = jobs[unit.values[JOB]]
					
					delunit(unit.target)
					delunit(unit.target2)
					unit.target = 0
					unit.target2 = 0
					unit.reserved = false
					unit.workstep = 0
					unit.work = ""
					
					energy = energy + 1.0
				end
			end
		else
			cancelwork(unit.fixed)
		end
	elseif (name == "build") then
		if (unit.workstep == 0) then
			local i = mmf.newObject(unit.target)
			local yes = findpath_unititem(unit,i)
			
			if yes then
				unit.workstep = 1
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 1) then
			local i = mmf.newObject(unit.target)
			
			if (near(unit,i) == 1) then
				if (unit.wait < 250) then
					unit.wait = unit.wait + 1
				else
					unit.wait = 0
					
					local jobdata = jobs[unit.values[JOB]]
					
					if (i.strings[2] ~= "newhom") then
						local newid = MF_create("struct")
						local new = mmf.newObject(newid)
						new.values[XPOS] = math.floor(unit.values[XPOS] + 0.2)
						new.values[YPOS] = math.floor(unit.values[YPOS] + 0.2)
						new.strings[NAME] = i.strings[2]
						new.strings[DESC] = "Built thing"
						addstruct(newid)
					else
						local newid = MF_create("unit")
						local new = mmf.newObject(newid)
						new.values[XPOS] = math.floor(unit.values[XPOS] + 0.2)
						new.values[YPOS] = math.floor(unit.values[YPOS] + 0.2)
						new.strings[DESC] = "Homunculus"
						addunit(newid)
					end
					
					delunit(unit.target)
					unit.target = 0
					unit.target2 = 0
					unit.reserved = false
					unit.workstep = 0
					unit.work = ""
				end
			end
		else
			cancelwork(unit.fixed)
		end
	elseif (name == "sleep") then
		if (unit.wait < 200) then
			unit.wait = unit.wait + 1
		else
			unit.wait = 0
			unit.reserved = false
			unit.workstep = 0
			unit.work = ""
			unit.energy = unit.energy * 0.5 + 1500 + math.random(1000,2000)
		end
	elseif (name == "eat") then
		local i = mmf.newObject(unit.target)
				
		if (unit.workstep == 0) then
			local yes = findpath_unititem(unit,i)
			
			if yes then
				unit.workstep = 1
			else
				cancelwork(unit.fixed)
			end
		elseif (unit.workstep == 1) then
			if (near(unit,i) == 1) then
				if (unit.wait < 60) then
					unit.wait = unit.wait + 1
				else
					i.held = 0
					--s.target = 0
					delunit(unit.target)
					unit.target = 0
					unit.target2 = 0
					unit.reserved = false
					--s.reserved = false
					unit.workstep = 0
					unit.work = ""
					unit.wait = 0
					unit.hunger = unit.hunger + 1000 + math.random(1000,2000)
					unit.poop = math.random(500,1500)
				end
			else
				cancelwork(unit.fixed)
			end
		end
	end
end