Added a bunch of comments and documentation