Fixed a bug, cleaned some code up