Fixed a bunch of bugs.