Fixed a whole lot of bugs.