Added comments to describe how it works