Small bug fixes

just fixed some bugs and cleaned up some code