adds a lot of comments and cleans up some variable names