Fixed a lot of bugs.