Massively hacked by adding some helper classes

Now can represent conceptually pretty much anything. Totally
untested. Will break, almost certainly.