Fixed a few bugs. All tests run fine. Formatting still not done.