Fixed a lot of bugs.

See title.