Various changes, cleaned up some code, added comments to a lot of code.