Cleaned up a lot of the code