Fixed a few bugs and removed some unnecessary code