Cleaned up and commented a lot of code.