correct statistic, add comments, clean up code