add comments and rename a few variables