added a bunch of comments and did some formatting