Cleaning up some code, fixed a few things