rewrote comments to make it easier to understand