Still need to document a lot of functions, but I cleaned up and explained a lot of the code via comments.