Fixed some bugs and cleaned up a little