Fixed a could of bugs.