Added a bunch of comments to help follow the code later.