Fixed a bug, removed some unneeded code