anchor.diff:  	</ul>
   	</p>"}
   
  -/obj/item/weapon/book/manual/chembook/proc/list_intermediates(var/id, var/list/reactions)
  -	//world << "DEBUG: LIST_INTERMEDIATES CALLED"
  -	for (var/datum/chemical_reaction/C in reactions)
  -		//world << "DEBUG: [C.id] == [id]"
  -		if (C.id == id)
  -			//world << "DEBUG: MATCH FOUND, WRITING RECIPE"
  -			dat += {"<ul>"}
  -			//dat += {"<li>DEBUG: INTERMEDIATE FOR [id]</li>"}
  -			src.list_reagents(id, reactions)
  -			dat += {"</ul>"}
  -			break
  -	return
  -
  -/obj/item/weapon/book/manual/chembook/proc/list_reagents(var/id, var/list/reactions)
  -	//world << "DEBUG: LIST_REAGENTS CALLED"
  -	for (var/datum/chemical_reaction/C in reactions)
  -		if (C.id == id)
  -			//world << "DEBUG: WRITING [C.id]"
  -			var/list/reagents = C.required_reagents
  -			var/list/catalysts = C.required_catalysts
  -			for (var/x in reagents)
  -				dat += {"<li>[reagents[x]] parts [id_to_name(x)]</li>"}
  -				src.list_intermediates(x, reactions)
  -			for (var/x in catalysts)
  -				dat += {"<li>Catalyst: [catalysts[x]] units of [id_to_name(x)]</li>"}
  -				src.list_intermediates(x, reactions)
  +	var/static/base_case = 0
  +	var/static/recursive_case = 0
  +	var/static/lookup_case = 0
  +
  +//Calculate the reactions list, or return it if already calculated (saves time).
  +/obj/item/weapon/book/manual/chembook/proc/get_reactions()
  +	if (!reactions.len)
  +		var/paths = typesof(/datum/chemical_reaction) - /datum/chemical_reaction
  +		for(var/path in paths)
  +			var/datum/chemical_reaction/reaction = new path()
  +			reactions[reaction.id] = reaction
  +	return reactions
  +
  +//As chembook may be spawned before /datum/reagents, make sure the global list is instantiated.
  +/obj/item/weapon/book/manual/chembook/proc/get_reagents()
  +	if (!chemical_reagents_list)
  +		//This instantiates the global reagents list. See source for reasoning.
  +		new /datum/reagents
  +	return chemical_reagents_list
  +
  +/obj/item/weapon/book/manual/chembook/proc/add_reaction(var/datum/chemical_reaction/reaction)
  +	if(!reaction.category in allowed_categories)
  +		return 0
  +	content += {"
  +		<tr><td><center>[reaction.name]</center></td>
  +		<td>
  +		[get_reagent_entry(reaction.id, toplevel=1)]
  +	  	</td>
  +	  	<td><center>[(reaction.result && reaction.result_amount)? reaction.result_amount : "N/A"]</center></td>
  +		</tr>
  +	"}
  +
  +/obj/item/weapon/book/manual/chembook/proc/get_reagent_entry(var/id, var/quantity=1, var/toplevel=0)
  +	var/datum/chemical_reaction/reaction = reactions[id]
  +	//No reaction, we're a base element.
  +	if (!reaction)
  +		base_case += 1
  +		return "<li>[quantity] parts [id_to_name(id)]</li>\n"
  +
  +	var/reagent_entry = ""
  +	if (!toplevel)
  +		reagent_entry += "<li>[quantity] parts [id_to_name(id)] - 1 part is made by: </li>\n"
  +	var/dependencies_entry = reagent_dependencies[id]
  +	if (!dependencies_entry)
  +		recursive_case += 1
  +		dependencies_entry = "<ul>\n"
  +		var/list/dependencies = (reaction.required_reagents + reaction.required_catalysts) - id
  +		for(var/reagent in dependencies)
  +			dependencies_entry += get_reagent_entry(reagent, dependencies[reagent])
  +		dependencies_entry += "</ul>\n"
  +	else
  +		lookup_case += 1
  +	reagent_dependencies[id] = dependencies_entry
  +	return reagent_entry + dependencies_entry
   
   /obj/item/weapon/book/manual/chembook/proc/id_to_name(var/id)
  -	var/datum/reagent/C
  -	for (var/R in typesof(/datum/reagent/))
  -		C = new R(src)
  -		if (C.id == id)
  -			return C.name
  -		else qdel(C)
  -	return "ERROR: NO MATCH"
  +	var/list/datum/reagent/reagents = get_reagents()
  +	var/datum/reagent/reagent = reagents[id]
  +	if (reagent)
  +		return reagent.name
  +	return 0
   
   /obj/item/weapon/book/manual/chembook/proc/alphasort(list/datum/chemical_reaction/L)
   //Creating this because the already made procs in this source were failing to return any data.
  
positive.code: 				<th>Resulting Amount</th>
  			</tr>"}
  
  	for (var/datum/chemical_reaction/C in reactions)
  		dat += {"<tr><td><center>[C.name]</center></td>"}
  		dat += {"<td>"}
  		src.list_intermediates(C.id, reactions)
  		dat += {"</td>"}
  		if (C.result && C.result_amount)
  			dat += {"<td><center>[C.result_amount]</center></td>"}
  		else
  			dat += {"<td><center>N/A</center></td>"}
  		dat += {"</tr>"}
  
  
  	for (var/G in reactions)
  		qdel(G) // Bye bye!
  	file(booksave) << dat //Save it all so we don't do this again.
  	return
  
  //bar needs love too ~Flavo
  /obj/item/weapon/book/manual/chembook/barman_recipes
  
negative.code: 				continue
  	return L
  
  /obj/item/weapon/book/manual/chembook/New()
  	var/list/reactions = get_reactions()
  
  	//We now have a list of all reactions, on to the formatting!
  
  