anchor.diff:  /obj/structure/table/proc/del_reqs(datum/table_recipe/TR)
   	var/datum/table_recipe/R = TR
   	for(var/A in R.reqs)
  -		var/obj/item/I = locate(A) in loc
  -		if(istype(I, /obj/item/stack))
  -			var/obj/item/stack/S = I
  -			S.amount -= R.reqs[A]
  -		else
  -			for(var/i=R.reqs[A],i>=0,i--)
  -				I = locate(A) in loc
  -				del(I)
  +		var/AP = text2path(A)
  +		var/BP
  +		world.log << "[A]"
  +		if(ispath(AP, /obj/item/stack))
  +			var/obj/item/stack/S
  +			for(var/B in table_contents)
  +				BP = text2path(B)
  +				if(ispath(BP, AP))
  +					S = locate(BP) in loc
  +					if(S.amount >= R.reqs[A])
  +						S.use(R.reqs[A])
  +						break
  +		else
  +			var/obj/item/I
  +			for(var/B in table_contents)
  +				BP = text2path(B)
  +				if(ispath(BP, AP))
  +					I = locate(BP) in loc
  +					if(I)
  +						del(I)
  +						break
   
   /obj/structure/table/interact(mob/user)
   	check_table()
  
positive.code: /obj/structure/table/proc/construct_item(mob/user, datum/table_recipe/TR)
  	check_table()
  	if(check_contents(TR) && check_tools(user, TR))
  		if(do_after(user, TR.time))
  			if(!check_contents(TR) || !check_tools(user, TR))
  				return 0
  			del_reqs(TR)
  			var/obj/item/I = new TR.result_path
  			I.loc = loc
  			return 1
  	return 0
  
negative.code: /obj/structure/table/proc/check_contents(datum/table_recipe/TR)
  	check_table()
  	var/datum/table_recipe/R = TR
  	var/I = R.reqs.len
  	var/i = R.reqs.len
  	world.log << "[i]"
  	for(var/A in R.reqs)
  		var/AP = text2path(A)
  		for(var/B in table_contents)
  			var/BP = text2path(B)
  			world.log << "[AP] - [BP]"
  			if(ispath(BP, AP))
  				world.log << "[i]"
  				if(table_contents[B] >= R.reqs[A])
  					i--
  					break
  		I--
  		if(i > I)
  			return 0
  	world.log << "[i]"
  	return !i
  
  /obj/structure/table/proc/check_table()
  	table_contents = list()
  	for(var/obj/item/I in loc)
  		if(istype(I, /obj/item/stack))
  			var/obj/item/stack/S = I
  			table_contents["[I.type]"] = (table_contents[I.type] ? (table_contents[I.type] + S.amount) : S.amount)
  		else
  			table_contents["[I.type]"] = (table_contents[I.type] ? (table_contents[I.type] + 1) : 1)
  
  /obj/structure/table/proc/check_tools(mob/user, datum/table_recipe/TR)
  	world.log << "Tools checking"
  	if(!TR.tools.len)
  		return 1
  	var/list/possible_tools = list()
  	for(var/obj/item/I in user.contents)
  		if(istype(I, /obj/item/weapon/storage))
  			for(var/obj/item/SI in I.contents)
  				possible_tools |= (SI.type)
  		else
  			possible_tools |= (I.type)
  	for(var/obj/item/TI in loc)
  		possible_tools |= (TI.type)
  	var/i = TR.tools.len
  	for(var/A in TR.tools)
  		if(possible_tools.Find(A))
  			possible_tools.Remove(A)
  			i--
  		else
  			break
  