Did a little cleanup, fixed some bugs