Fixed a few bugs, no tests so not worth much. Some things are going to be hard to test.