Fixed a series of silly bugs.