Added a bunch of comments and explanations for a lot of code.