Fixed a bunch of significant bugs.