Made everything work after a bugger of an evening

It works using depth first search at the moment. Please don't change
anything quite yet, before speaking to me.