Fixed a few horrific bugs