whole heap of refactoring and stuff. Much nicer now!