Fixed a few things, cleaned up the code