Fixed a couple of things. Needs tests.