Cleaned up the code, and removed most of the code that was unused